001: package net.firstpartners.nounit.snippet.test;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026: import java.util.Iterator;
027:
028: import junit.framework.Test;
029: import junit.framework.TestCase;
030: import junit.framework.TestSuite;
031: import net.firstpartners.nounit.snippet.Snippets;
032: import net.firstpartners.nounit.snippet.xml.IXmlSource;
033: import org.apache.log4j.Logger;
034:
035: /**
036: * Test the Class Snippet Package<BR>
037: *
038: */
039: public class TestSnippetCalls extends TestCase {
040:
041: //handle to logger
042: static Logger log = Logger.getLogger(TestSnippetCalls.class);
043:
044: /**
045: * Constructor as required by Junit
046: * @param name to be displayed on testrunner
047: */
048: public TestSnippetCalls(String name) {
049: super (name);
050: }
051:
052: /**
053: * Code run before each test
054: */
055: public void setUp() {
056:
057: }
058:
059: /**
060: * Code run after each test
061: */
062: protected void tearDown() {
063:
064: }
065:
066: /**
067: * Enable Junit to run this Class individually
068: * @param args
069: */
070: public static void main(String[] args) {
071: junit.textui.TestRunner.run(suite());
072: }
073:
074: /**
075: * Enable Junit to run this class as part of AllTests.java
076: * @return TestSuite
077: */
078: public static Test suite() {
079: return new TestSuite(TestSnippetCalls.class);
080: }
081:
082: /**
083: * Test XML Output
084: */
085: public void testSnippetCalledMethodXml() throws Exception {
086:
087: //Local Variables
088: IXmlSource this XmlSource;
089: Iterator loop;
090: String tmpString;
091: StringBuffer results = new StringBuffer();
092:
093: //Get Test Data
094: Snippets someMethods = TestSnippetData
095: .getSnippetCalledMethods();
096:
097: loop = someMethods.getIterator();
098: while (loop.hasNext()) {
099:
100: //Add the XML in this method
101: this XmlSource = (IXmlSource) loop.next();
102: results.append(this XmlSource.toXml());
103: results.append("\n");
104:
105: }
106:
107: //Now check if the results are as expected
108: tmpString = results.toString();
109:
110: log.debug(tmpString);
111: int oldPlaceHolder = -1;
112: int placeHolder = -1;
113:
114: //Assert that each of the following tests come after the previous
115: oldPlaceHolder = placeHolder;
116: placeHolder = tmpString.indexOf("<CALLS");
117: assertTrue(placeHolder > oldPlaceHolder);
118:
119: oldPlaceHolder = placeHolder;
120: placeHolder = tmpString.indexOf("<CLASS");
121: assertTrue(placeHolder > oldPlaceHolder);
122:
123: oldPlaceHolder = placeHolder;
124: placeHolder = tmpString.indexOf("<METHOD");
125: assertTrue(placeHolder > oldPlaceHolder);
126:
127: oldPlaceHolder = placeHolder;
128: placeHolder = tmpString.indexOf("<PARAM");
129: assertTrue(placeHolder > oldPlaceHolder);
130: }
131:
132: }
|