001: /*
002: * This file is part of "SnipSnap Radeox Rendering Engine".
003: *
004: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
005: * All Rights Reserved.
006: *
007: * Please visit http://radeox.org/ for updates and contact.
008: *
009: * --LICENSE NOTICE--
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * --LICENSE NOTICE--
022: */
023: package org.radeox.test.macro.list;
024:
025: import java.io.IOException;
026: import java.util.Arrays;
027: import java.util.Collection;
028:
029: import junit.framework.Test;
030: import junit.framework.TestSuite;
031:
032: import org.radeox.macro.list.SimpleList;
033: import org.radeox.util.Linkable;
034: import org.radeox.util.Nameable;
035:
036: public class SimpleListTest extends ListFormatterSupport {
037: public SimpleListTest(String name) {
038: super (name);
039: }
040:
041: public static Test suite() {
042: return new TestSuite(SimpleListTest.class);
043: }
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047: formatter = new SimpleList();
048: }
049:
050: public void testNameable() {
051: Collection c = Arrays.asList(new Nameable[] { new Nameable() {
052: public String getName() {
053: return "name:test";
054: }
055: } });
056: try {
057: formatter.format(writer, emptyLinkable, "", c, "", false);
058: } catch (IOException e) {
059: e.printStackTrace();
060: }
061:
062: assertEquals(
063: "Nameable is rendered",
064: "<div class=\"list\"><div class=\"list-title\"></div><blockquote>name:test</blockquote></div>",
065: writer.toString());
066: }
067:
068: public void testLinkable() {
069: Collection c = Arrays.asList(new Linkable[] { new Linkable() {
070: public String getLink() {
071: return "link:test";
072: }
073: } });
074: try {
075: formatter.format(writer, emptyLinkable, "", c, "", false);
076: } catch (IOException e) {
077: e.printStackTrace();
078: }
079:
080: assertEquals(
081: "Linkable is rendered",
082: "<div class=\"list\"><div class=\"list-title\"></div><blockquote>link:test</blockquote></div>",
083: writer.toString());
084: }
085:
086: public void testSingeItem() {
087: Collection c = Arrays.asList(new String[] { "test" });
088: try {
089: formatter.format(writer, emptyLinkable, "", c, "", false);
090: } catch (IOException e) {
091: e.printStackTrace();
092: }
093: assertEquals(
094: "Single item is rendered",
095: "<div class=\"list\"><div class=\"list-title\"></div><blockquote>test</blockquote></div>",
096: writer.toString());
097: }
098:
099: public void testSize() {
100: Collection c = Arrays.asList(new String[] { "test" });
101: try {
102: formatter.format(writer, emptyLinkable, "", c, "", true);
103: } catch (IOException e) {
104: e.printStackTrace();
105: }
106: assertEquals(
107: "Size is rendered",
108: "<div class=\"list\"><div class=\"list-title\"> (1)</div><blockquote>test</blockquote></div>",
109: writer.toString());
110: }
111:
112: public void testEmpty() {
113: Collection c = Arrays.asList(new String[] {});
114: try {
115: formatter.format(writer, emptyLinkable, "", c, "No items",
116: false);
117: } catch (IOException e) {
118: e.printStackTrace();
119: }
120: assertEquals(
121: "Empty list is rendered",
122: "<div class=\"list\"><div class=\"list-title\"></div>No items</div>",
123: writer.toString());
124: }
125:
126: public void testTwoItems() {
127: Collection c = Arrays.asList(new String[] { "test1", "test2" });
128: try {
129: formatter.format(writer, emptyLinkable, "", c, "", false);
130: } catch (IOException e) {
131: e.printStackTrace();
132: }
133: assertEquals(
134: "Two items are rendered",
135: "<div class=\"list\"><div class=\"list-title\"></div><blockquote>test1, test2</blockquote></div>",
136: writer.toString());
137: }
138:
139: }
|