001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: public class TestLoadListenerVisitorAdapter extends TestCase implements
041: Visitor {
042: public static final String TEST_DIR = "tests" + File.separator
043: + "JarJarDiff";
044: public static final String TEST_CLASS = "test";
045: public static final String TEST_FILENAME = "classes"
046: + File.separator + "test.class";
047:
048: private LinkedList<Classfile> classfiles;
049: private ClassfileLoader loader;
050:
051: protected void setUp() throws Exception {
052: classfiles = new LinkedList<Classfile>();
053:
054: LoadListenerVisitorAdapter adapter = new LoadListenerVisitorAdapter(
055: this );
056: loader = new AggregatingClassfileLoader();
057: loader.addLoadListener(adapter);
058: }
059:
060: public void testOneFile() {
061: loader.load(TEST_FILENAME);
062:
063: assertEquals("First class", TEST_CLASS, classfiles.getFirst()
064: .getClassName());
065: assertEquals("Nb visited classes", 1, classfiles.size());
066: }
067:
068: public void testManyFiles() {
069: loader.load(TEST_DIR);
070:
071: assertEquals("Nb visited classes", 164, classfiles.size());
072: }
073:
074: public void visitClassfiles(Collection<Classfile> classfiles) {
075: this .classfiles.addAll(classfiles);
076: }
077:
078: public void visitClassfile(Classfile classfile) {
079: classfiles.add(classfile);
080: }
081:
082: public void visitConstantPool(ConstantPool constantPool) {
083: // Do nothing
084: }
085:
086: public void visitClass_info(Class_info entry) {
087: // Do nothing
088: }
089:
090: public void visitFieldRef_info(FieldRef_info entry) {
091: // Do nothing
092: }
093:
094: public void visitMethodRef_info(MethodRef_info entry) {
095: // Do nothing
096: }
097:
098: public void visitInterfaceMethodRef_info(
099: InterfaceMethodRef_info entry) {
100: // Do nothing
101: }
102:
103: public void visitString_info(String_info entry) {
104: // Do nothing
105: }
106:
107: public void visitInteger_info(Integer_info entry) {
108: // Do nothing
109: }
110:
111: public void visitFloat_info(Float_info entry) {
112: // Do nothing
113: }
114:
115: public void visitLong_info(Long_info entry) {
116: // Do nothing
117: }
118:
119: public void visitDouble_info(Double_info entry) {
120: // Do nothing
121: }
122:
123: public void visitNameAndType_info(NameAndType_info entry) {
124: // Do nothing
125: }
126:
127: public void visitUTF8_info(UTF8_info entry) {
128: // Do nothing
129: }
130:
131: public void visitField_info(Field_info entry) {
132: // Do nothing
133: }
134:
135: public void visitMethod_info(Method_info entry) {
136: // Do nothing
137: }
138:
139: public void visitConstantValue_attribute(
140: ConstantValue_attribute attribute) {
141: // Do nothing
142: }
143:
144: public void visitCode_attribute(Code_attribute attribute) {
145: // Do nothing
146: }
147:
148: public void visitExceptions_attribute(Exceptions_attribute attribute) {
149: // Do nothing
150: }
151:
152: public void visitInnerClasses_attribute(
153: InnerClasses_attribute attribute) {
154: // Do nothing
155: }
156:
157: public void visitSynthetic_attribute(Synthetic_attribute attribute) {
158: // Do nothing
159: }
160:
161: public void visitSourceFile_attribute(SourceFile_attribute attribute) {
162: // Do nothing
163: }
164:
165: public void visitLineNumberTable_attribute(
166: LineNumberTable_attribute attribute) {
167: // Do nothing
168: }
169:
170: public void visitLocalVariableTable_attribute(
171: LocalVariableTable_attribute attribute) {
172: // Do nothing
173: }
174:
175: public void visitDeprecated_attribute(Deprecated_attribute attribute) {
176: // Do nothing
177: }
178:
179: public void visitCustom_attribute(Custom_attribute attribute) {
180: // Do nothing
181: }
182:
183: public void visitInstruction(Instruction instruction) {
184: // Do nothing
185: }
186:
187: public void visitExceptionHandler(ExceptionHandler helper) {
188: // Do nothing
189: }
190:
191: public void visitInnerClass(InnerClass helper) {
192: // Do nothing
193: }
194:
195: public void visitLineNumber(LineNumber helper) {
196: // Do nothing
197: }
198:
199: public void visitLocalVariable(LocalVariable helper) {
200: // Do nothing
201: }
202: }
|