KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30
31 import org.apache.log4j.Logger;
32
33 import org.gjt.jclasslib.structures.AttributeInfo;
34 import org.gjt.jclasslib.structures.ClassFile;
35 import org.gjt.jclasslib.structures.MethodInfo;
36 import org.gjt.jclasslib.structures.attributes.CodeAttribute;
37
38 import net.firstpartners.nounit.reader.bytecode.ByteCodeCallsSnippetFactory;
39 import net.firstpartners.nounit.test.TestData;
40
41 /**
42  * Test the Method Snippet Factory<BR>
43  *
44  */

45 public class TestByteCodeCallsSnippetFactory extends TestCase {
46     
47     //handle to logger
48
static Logger log = Logger.getLogger(TestByteCodeCallsSnippetFactory.class);
49     
50     /**
51      * Constructor as required by Junit
52      * @param name to be displayed on testrunner
53      */

54     public TestByteCodeCallsSnippetFactory(String JavaDoc name) {
55         super(name);
56     }
57     
58     /**
59      * Code run before each test
60      */

61     public void setUp(){
62         
63     }
64     
65     /**
66      * Code run after each test
67      */

68     protected void tearDown() {
69         
70     }
71     
72     /**
73      * Enable Junit to run this Class individually
74      * @param args
75      */

76     public static void main(String JavaDoc[] args) {
77         junit.textui.TestRunner.run(suite());
78     }
79     
80     /**
81      * Enable Junit to run this class as part of AllTests.java
82      * @return TestSuite
83      */

84     public static Test suite() {
85         return new TestSuite(TestByteCodeCallsSnippetFactory.class);
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         //Handle to class to be tested
94
ByteCodeCallsSnippetFactory testByteCode;
95         AttributeInfo[] myAttributes;
96         CodeAttribute tmpCodeAttribute;
97         
98         //Handle to the source - needed for reading byte code
99
ClassFile classSource = TestData.getSampleClassFile();
100                
101         //Get Information about File
102
MethodInfo[] myMethods = classSource.getMethods();
103         
104         //Keep output
105
StringBuffer JavaDoc output = new StringBuffer JavaDoc();
106         
107         
108         //Loop through Information and get class source
109
for (int a=0;a<myMethods.length; a++) {
110             
111             myAttributes = myMethods[a].getAttributes();
112             
113             for (int b=0; b<myAttributes.length;b++) {
114                 
115                 //Only Do this if it is a code attribute -
116
if (myAttributes[b] instanceof CodeAttribute){
117                     
118                     tmpCodeAttribute = (CodeAttribute)myAttributes[b];
119                     testByteCode = new ByteCodeCallsSnippetFactory(tmpCodeAttribute,classSource);
120                    
121                     //append for later assertions
122
//output.append(testByteCode.getSnippets());
123
output.append(testByteCode.getSnippets().toXml());
124                     
125                    
126                 } // end-if
127

128             } // end b-loop
129

130         } // end a-loop
131

132         log.debug(output);
133         
134         String JavaDoc info = output.toString();
135         
136         assertTrue(info.indexOf("<CALLS class=")>-1);
137         assertTrue(info.indexOf("method=")>-1);
138
139     }
140     
141 }
142
Popular Tags