KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32 import net.firstpartners.nounit.reader.ISnippetFactory;
33 import net.firstpartners.nounit.reader.bytecode.ByteCodeMethodSnippetFactory;
34 import net.firstpartners.nounit.snippet.Snippets;
35 import net.firstpartners.nounit.test.TestData;
36 import org.apache.log4j.Logger;
37 /**
38  * Test the Method Snippet Factory<BR>
39
40  */

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

50     public TestByteCodeMethodSnippetFactory(String JavaDoc name) {
51     super(name);
52   }
53
54   /**
55    * Code run before each test
56    */

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

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

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

81   public static Test suite() {
82       return new TestSuite(TestByteCodeMethodSnippetFactory.class);
83   }
84   
85   /**
86    * Test the breaking of the parameter String (tag info) into Hashtable
87    */

88   public void testParameterStringConversion() throws Exception JavaDoc {
89       
90       String JavaDoc tmpString;
91       String JavaDoc testString="<(Ljava/lang/String;Ljava/lang/String;Lorg/jdom/Namespace;)Lorg/jdom/Attirbute;>";
92       ByteCodeMethodSnippetFactory myFactory =
93             new ByteCodeMethodSnippetFactory(TestData.getSampleClassFile());
94       
95       HashMap JavaDoc results= myFactory.splitTagVerboseIntoHashMap(testString);
96       Iterator JavaDoc loop = results.keySet().iterator();
97       
98
99       assertTrue(results.get("0").equals("java.lang.String"));
100       assertTrue(results.get("1").equals("java.lang.String"));
101       assertTrue(results.get("2").equals("org.jdom.Namespace"));
102       assertTrue(results.get("3").equals("org.jdom.Attirbute"));
103             
104   }
105
106   public void testConvertMethodsAsSnippets() throws Exception JavaDoc {
107       
108       Snippets javaInformation;
109       Iterator JavaDoc informationList;
110       ISnippetFactory myFactory =
111             new ByteCodeMethodSnippetFactory(TestData.getSampleClassFile());
112                
113       //Get Information about File
114
javaInformation = myFactory.getSnippets();
115       informationList = javaInformation.getIterator();
116       
117       while (informationList.hasNext()) {
118       // assertTrue(informationList.next() instanceof ISnippet);
119
log.debug(informationList.next().getClass());
120       }
121       
122   }
123
124
125 }
Popular Tags