001: package net.firstpartners.nounit.reader.bytecode.test;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030:
031: import org.apache.log4j.Logger;
032:
033: import org.gjt.jclasslib.structures.AttributeInfo;
034: import org.gjt.jclasslib.structures.ClassFile;
035: import org.gjt.jclasslib.structures.MethodInfo;
036: import org.gjt.jclasslib.structures.attributes.CodeAttribute;
037:
038: import net.firstpartners.nounit.reader.bytecode.ByteCodeCallsSnippetFactory;
039: import net.firstpartners.nounit.test.TestData;
040:
041: /**
042: * Test the Method Snippet Factory<BR>
043: *
044: */
045: public class TestByteCodeCallsSnippetFactory extends TestCase {
046:
047: //handle to logger
048: static Logger log = Logger
049: .getLogger(TestByteCodeCallsSnippetFactory.class);
050:
051: /**
052: * Constructor as required by Junit
053: * @param name to be displayed on testrunner
054: */
055: public TestByteCodeCallsSnippetFactory(String name) {
056: super (name);
057: }
058:
059: /**
060: * Code run before each test
061: */
062: public void setUp() {
063:
064: }
065:
066: /**
067: * Code run after each test
068: */
069: protected void tearDown() {
070:
071: }
072:
073: /**
074: * Enable Junit to run this Class individually
075: * @param args
076: */
077: public static void main(String[] args) {
078: junit.textui.TestRunner.run(suite());
079: }
080:
081: /**
082: * Enable Junit to run this class as part of AllTests.java
083: * @return TestSuite
084: */
085: public static Test suite() {
086: return new TestSuite(TestByteCodeCallsSnippetFactory.class);
087: }
088:
089: /**
090: * Test the breaking of the parameter String (tag info) into Hashtable
091: */
092: public void testParameterStringConversion() throws Exception {
093:
094: //Handle to class to be tested
095: ByteCodeCallsSnippetFactory testByteCode;
096: AttributeInfo[] myAttributes;
097: CodeAttribute tmpCodeAttribute;
098:
099: //Handle to the source - needed for reading byte code
100: ClassFile classSource = TestData.getSampleClassFile();
101:
102: //Get Information about File
103: MethodInfo[] myMethods = classSource.getMethods();
104:
105: //Keep output
106: StringBuffer output = new StringBuffer();
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(
120: tmpCodeAttribute, classSource);
121:
122: //append for later assertions
123: //output.append(testByteCode.getSnippets());
124: output.append(testByteCode.getSnippets().toXml());
125:
126: } // end-if
127:
128: } // end b-loop
129:
130: } // end a-loop
131:
132: log.debug(output);
133:
134: String info = output.toString();
135:
136: assertTrue(info.indexOf("<CALLS class=") > -1);
137: assertTrue(info.indexOf("method=") > -1);
138:
139: }
140:
141: }
|