1 25 package org.snipsnap.test.render.macro.list; 26 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 30 import org.snipsnap.render.macro.list.SimpleList; 31 import org.snipsnap.render.macro.list.Nameable; 32 import org.snipsnap.render.macro.list.Linkable; 33 34 import java.io.IOException ; 35 import java.util.Arrays ; 36 import java.util.Collection ; 37 38 public class SimpleListTest extends ListFormatterSupport { 39 public SimpleListTest(String name) { 40 super(name); 41 } 42 43 public static Test suite() { 44 return new TestSuite(SimpleListTest.class); 45 } 46 47 protected void setUp() throws Exception { 48 super.setUp(); 49 formatter = new SimpleList(); 50 } 51 52 public void testNameable() { 53 Collection c = Arrays.asList(new Nameable[]{ 54 new Nameable() { 55 public String getName() { 56 return "name:test"; 57 } 58 } 59 }); 60 try { 61 formatter.format(writer, emptyLinkable, "", c, "", false); 62 } catch (IOException e) { 63 e.printStackTrace(); 64 } 65 66 assertEquals("Nameable is rendered", 67 "<div class=\"list\"><div class=\"list-title\"></div><blockquote>name:test</blockquote></div>", 68 writer.toString()); 69 } 70 71 public void testLinkable() { 72 Collection c = Arrays.asList(new Linkable[]{ 73 new Linkable() { 74 public String getLink() { 75 return "link:test"; 76 } 77 } 78 }); 79 try { 80 formatter.format(writer, emptyLinkable, "", c, "", false); 81 } catch (IOException e) { 82 e.printStackTrace(); 83 } 84 85 assertEquals("Linkable is rendered", 86 "<div class=\"list\"><div class=\"list-title\"></div><blockquote>link:test</blockquote></div>", 87 writer.toString()); 88 } 89 90 public void testSingeItem() { 91 Collection c = Arrays.asList(new String []{"test"}); 92 try { 93 formatter.format(writer,emptyLinkable, "", c, "", false); 94 } catch (IOException e) { 95 e.printStackTrace(); 96 } 97 assertEquals("Single item is rendered", 98 "<div class=\"list\"><div class=\"list-title\"></div><blockquote>test</blockquote></div>", 99 writer.toString()); 100 } 101 102 103 public void testSize() { 104 Collection c = Arrays.asList(new String []{"test"}); 105 try { 106 formatter.format(writer, emptyLinkable, "", c, "", true); 107 } catch (IOException e) { 108 e.printStackTrace(); 109 } 110 assertEquals("Size is rendered", 111 "<div class=\"list\"><div class=\"list-title\"> (1)</div><blockquote>test</blockquote></div>", 112 writer.toString()); 113 } 114 115 public void testEmpty() { 116 Collection c = Arrays.asList(new String []{}); 117 try { 118 formatter.format(writer, emptyLinkable, "", c, "No items", false); 119 } catch (IOException e) { 120 e.printStackTrace(); 121 } 122 assertEquals("Empty list is rendered", 123 "<div class=\"list\"><div class=\"list-title\"></div>No items</div>", 124 writer.toString()); 125 } 126 127 public void testTwoItems() { 128 Collection c = Arrays.asList(new String []{"test1", "test2"}); 129 try { 130 formatter.format(writer, emptyLinkable, "", c, "", false); 131 } catch (IOException e) { 132 e.printStackTrace(); 133 } 134 assertEquals("Two items are rendered", 135 "<div class=\"list\"><div class=\"list-title\"></div><blockquote>test1, test2</blockquote></div>", 136 writer.toString()); 137 } 138 139 } 140 | Popular Tags |