001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: public class TestHTMLCyclePrinter extends TestHTMLPrinterBase {
039: private HTMLCyclePrinter visitor;
040:
041: private Node a_package;
042: private Node b_package;
043: private Node c_package;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: visitor = new HTMLCyclePrinter(new PrintWriter(out), FORMAT);
049:
050: a_package = factory.createPackage("a");
051: b_package = factory.createPackage("b");
052: c_package = factory.createPackage("c");
053: }
054:
055: public void testEmptyCycles() throws IOException {
056: visitor.visitCycles(Collections.EMPTY_LIST);
057:
058: BufferedReader in = new BufferedReader(new StringReader(out
059: .toString()));
060:
061: assertEquals("End of file", null, in.readLine());
062: }
063:
064: public void test2NodesCycle() throws IOException {
065: List<Node> nodes = new ArrayList<Node>();
066: nodes.add(a_package);
067: nodes.add(b_package);
068: Cycle cycle = new Cycle(nodes);
069:
070: visitor.visitCycles(Collections.singletonList(cycle));
071:
072: int lineNumber = 0;
073: BufferedReader in = new BufferedReader(new StringReader(out
074: .toString()));
075:
076: assertEquals("line " + ++lineNumber,
077: "<a class=\"scope\" href=\"" + PREFIX + "a" + SUFFIX
078: + "\" id=\"a\">a</a>", in.readLine());
079: assertEquals("line " + ++lineNumber, " --> <a href=\""
080: + PREFIX + "b" + SUFFIX + "\" id=\"a_to_b\">b</a>", in
081: .readLine());
082: assertEquals("line " + ++lineNumber,
083: " --> <a href=\"" + PREFIX + "a" + SUFFIX
084: + "\" id=\"b_to_a\">a</a>", in.readLine());
085:
086: assertEquals("End of file", null, in.readLine());
087: }
088:
089: public void test3NodesCycle() throws IOException {
090: List<Node> nodes = new ArrayList<Node>();
091: nodes.add(a_package);
092: nodes.add(b_package);
093: nodes.add(c_package);
094: Cycle cycle = new Cycle(nodes);
095:
096: visitor.visitCycles(Collections.singletonList(cycle));
097:
098: int lineNumber = 0;
099: BufferedReader in = new BufferedReader(new StringReader(out
100: .toString()));
101:
102: assertEquals("line " + ++lineNumber,
103: "<a class=\"scope\" href=\"" + PREFIX + "a" + SUFFIX
104: + "\" id=\"a\">a</a>", in.readLine());
105: assertEquals("line " + ++lineNumber, " --> <a href=\""
106: + PREFIX + "b" + SUFFIX + "\" id=\"a_to_b\">b</a>", in
107: .readLine());
108: assertEquals("line " + ++lineNumber,
109: " --> <a href=\"" + PREFIX + "c" + SUFFIX
110: + "\" id=\"b_to_c\">c</a>", in.readLine());
111: assertEquals("line " + ++lineNumber,
112: " --> <a href=\"" + PREFIX + "a" + SUFFIX
113: + "\" id=\"c_to_a\">a</a>", in.readLine());
114:
115: assertEquals("End of file", null, in.readLine());
116: }
117: }
|