KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > reader > bytecode > test > TestByteCodeClassSnippetFactory


1 package net.firstpartners.nounit.reader.bytecode.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.io.File JavaDoc;
27
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31 import net.firstpartners.nounit.reader.ISnippetFactory;
32 import net.firstpartners.nounit.reader.bytecode.AbstractByteCodeSnippetFactory;
33 import net.firstpartners.nounit.reader.bytecode.ByteCodeClassSnippetFactory;
34 import net.firstpartners.nounit.snippet.Snippets;
35 import net.firstpartners.nounit.test.TestData;
36
37 /**
38  * Test the Class Snippet Factory<BR>
39  */

40 public class TestByteCodeClassSnippetFactory extends TestCase {
41
42     /**
43      * Constructor as required by Junit.
44      * @param name to be displayed on testrunner
45      */

46     public TestByteCodeClassSnippetFactory(String JavaDoc name) {
47         super(name);
48     }
49
50     /**
51      * Enable Junit to run this Class individually.
52      * @param args
53      */

54     public static void main(String JavaDoc[] args) {
55         junit.textui.TestRunner.run (suite());
56     }
57
58     /**
59      * Enable Junit to run this class as part of AllTests.java
60      * @return TestSuite
61      */

62     public static Test suite() {
63         return new TestSuite(TestByteCodeClassSnippetFactory.class);
64     }
65   
66     public void testGetClassInfo() throws Exception JavaDoc {
67       
68         //Local Variables
69
File JavaDoc sourceFile= new File JavaDoc( TestData.SAMPLE_CLASS_PROXY );
70
71         //Get Information about File & assert
72
ISnippetFactory myFactory =
73         new ByteCodeClassSnippetFactory( sourceFile );
74         Snippets javaInformation = myFactory.getSnippets();
75         String JavaDoc info = javaInformation.toString();
76       
77         assertTrue(info.indexOf("public eip.ProxyBean")>-1);
78         assertTrue(info.indexOf("handleGenericRequest(")>-1);
79         assertTrue(info.indexOf("main(")>-1);
80         assertTrue(info.indexOf("handleCommandLineRequest(")>-1);
81         assertTrue(info.indexOf("<init>(")>-1);
82         assertTrue(info.indexOf("clearError(")>-1);
83         assertTrue(info.indexOf("extends java.lang.Object")>-1);
84         assertTrue(info.indexOf("public")>-1);
85         assertTrue(info.indexOf("protected")>-1);
86     }
87   
88     /**
89      * Test the breaking of the parameter String (tag info) into Hashtable
90      */

91     public void testParameterStringConversion() throws Exception JavaDoc {
92
93         AbstractByteCodeSnippetFactory myFactory
94           = new ByteCodeClassSnippetFactory(TestData.getSampleFile());
95         String JavaDoc testString=".somepackage/someClass";
96         String JavaDoc results=myFactory.cleanValues(testString);
97       
98         assertTrue(results.equals("somepackage.someClass"));
99     }
100
101 }
102
Popular Tags