KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > test > render > macro > list > SimpleListTest


1 /*
2  * This file is part of "SnipSnap Radeox Rendering Engine".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://radeox.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.Collection JavaDoc;
37
38 public class SimpleListTest extends ListFormatterSupport {
39   public SimpleListTest(String JavaDoc 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 JavaDoc {
48     super.setUp();
49     formatter = new SimpleList();
50   }
51
52   public void testNameable() {
53     Collection JavaDoc c = Arrays.asList(new Nameable[]{
54       new Nameable() {
55         public String JavaDoc getName() {
56           return "name:test";
57         }
58       }
59     });
60     try {
61       formatter.format(writer, emptyLinkable, "", c, "", false);
62     } catch (IOException JavaDoc 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 JavaDoc c = Arrays.asList(new Linkable[]{
73       new Linkable() {
74         public String JavaDoc getLink() {
75           return "link:test";
76         }
77       }
78     });
79     try {
80       formatter.format(writer, emptyLinkable, "", c, "", false);
81     } catch (IOException JavaDoc 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 JavaDoc c = Arrays.asList(new String JavaDoc[]{"test"});
92     try {
93       formatter.format(writer,emptyLinkable, "", c, "", false);
94     } catch (IOException JavaDoc 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 JavaDoc c = Arrays.asList(new String JavaDoc[]{"test"});
105     try {
106       formatter.format(writer, emptyLinkable, "", c, "", true);
107     } catch (IOException JavaDoc 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 JavaDoc c = Arrays.asList(new String JavaDoc[]{});
117     try {
118       formatter.format(writer, emptyLinkable, "", c, "No items", false);
119     } catch (IOException JavaDoc 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 JavaDoc c = Arrays.asList(new String JavaDoc[]{"test1", "test2"});
129     try {
130       formatter.format(writer, emptyLinkable, "", c, "", false);
131     } catch (IOException JavaDoc 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