KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > snippet > test > TestSnippetCalls


1 package net.firstpartners.nounit.snippet.test;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26 import java.util.Iterator JavaDoc;
27
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31 import net.firstpartners.nounit.snippet.Snippets;
32 import net.firstpartners.nounit.snippet.xml.IXmlSource;
33 import org.apache.log4j.Logger;
34
35 /**
36  * Test the Class Snippet Package<BR>
37  *
38  */

39 public class TestSnippetCalls extends TestCase {
40     
41     //handle to logger
42
static Logger log = Logger.getLogger(TestSnippetCalls.class);
43     
44     /**
45      * Constructor as required by Junit
46      * @param name to be displayed on testrunner
47      */

48     public TestSnippetCalls(String JavaDoc name) {
49         super(name);
50     }
51     
52     /**
53      * Code run before each test
54      */

55     public void setUp(){
56         
57     }
58     
59     /**
60      * Code run after each test
61      */

62     protected void tearDown() {
63         
64     }
65     
66     /**
67      * Enable Junit to run this Class individually
68      * @param args
69      */

70     public static void main(String JavaDoc[] args) {
71         junit.textui.TestRunner.run(suite());
72     }
73     
74     /**
75      * Enable Junit to run this class as part of AllTests.java
76      * @return TestSuite
77      */

78     public static Test suite() {
79         return new TestSuite(TestSnippetCalls.class);
80     }
81     
82     /**
83      * Test XML Output
84      */

85     public void testSnippetCalledMethodXml() throws Exception JavaDoc {
86         
87         //Local Variables
88
IXmlSource thisXmlSource;
89         Iterator JavaDoc loop;
90         String JavaDoc tmpString;
91         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
92         
93         
94         //Get Test Data
95
Snippets someMethods = TestSnippetData.getSnippetCalledMethods();
96         
97         loop = someMethods.getIterator();
98         while (loop.hasNext()) {
99             
100             //Add the XML in this method
101
thisXmlSource=(IXmlSource)loop.next();
102             results.append(thisXmlSource.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     
133     
134 }
Popular Tags