KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Test the Class Snippet Package<BR>
36
37  */

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

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

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

61   protected void tearDown()
62   {
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(TestSnippetMethod.class);
80   }
81   
82     public void testSnippetMethodXml() throws Exception JavaDoc {
83       
84         //Local Variables
85
IXmlSource thisXmlSource;
86         Iterator JavaDoc loop;
87         String JavaDoc tmpString;
88         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
89         
90         
91         //Get Test Data
92
Snippets someMethods = TestSnippetData.getSnippetMethods();
93         
94         loop = someMethods.getIterator();
95         while (loop.hasNext()) {
96             
97             //Add the XML in this method
98
thisXmlSource=(IXmlSource)loop.next();
99             results.append(thisXmlSource.toXml());
100             results.append("\n");
101             
102         }
103         
104         //Now check if the results are as expected
105
tmpString = results.toString();
106          
107          log.debug(tmpString);
108          assertTrue(tmpString.indexOf("<METHOD name=")>-1);
109          assertTrue(tmpString.indexOf("access=")>-1);
110          assertTrue(tmpString.indexOf("<PARAM>")>-1);
111          assertTrue(tmpString.indexOf("<CLASS name=")>-1);
112          assertTrue(tmpString.indexOf("</PARAM>")>-1);
113          assertTrue(tmpString.indexOf("</METHOD")>-1);
114           
115   }
116   
117
118 }
Popular Tags