-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ABHAY0O7/core-test
Test for ASM working.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
depclean-core/src/test/java/se/kth/depclean/core/analysis/ASMTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package se.kth.depclean.core.analysis; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.objectweb.asm.AnnotationVisitor; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.FieldVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.signature.SignatureVisitor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import se.kth.depclean.core.analysis.asm.DefaultAnnotationVisitor; | ||
import se.kth.depclean.core.analysis.asm.DefaultClassVisitor; | ||
import se.kth.depclean.core.analysis.asm.DefaultFieldVisitor; | ||
import se.kth.depclean.core.analysis.asm.DefaultMethodVisitor; | ||
import se.kth.depclean.core.analysis.asm.DefaultSignatureVisitor; | ||
import se.kth.depclean.core.analysis.asm.ResultCollector; | ||
import se.kth.depclean.core.analysis.graph.ClassMembersVisitorCounter; | ||
|
||
@Slf4j | ||
public class ASMTest { | ||
|
||
// Resource class for testing. | ||
private static final File classFile = new File("src/test/resources/ClassFileVisitorResources/ExampleClass.class"); | ||
|
||
@Test | ||
@DisplayName("Test that the default asm classes are working fine.") | ||
void test_for_proper_asm_functioning() throws IOException { | ||
|
||
ResultCollector resultCollector = new ResultCollector(); | ||
FileInputStream fileInputStream = new FileInputStream(classFile); | ||
ClassReader reader = new ClassReader(fileInputStream); | ||
|
||
AnnotationVisitor annotationVisitor = new DefaultAnnotationVisitor(resultCollector); | ||
SignatureVisitor signatureVisitor = new DefaultSignatureVisitor(resultCollector); | ||
FieldVisitor fieldVisitor = new DefaultFieldVisitor( | ||
annotationVisitor, | ||
resultCollector | ||
); | ||
MethodVisitor methodVisitor = new DefaultMethodVisitor( | ||
annotationVisitor, | ||
signatureVisitor, | ||
resultCollector | ||
); | ||
DefaultClassVisitor defaultClassVisitor = new DefaultClassVisitor( | ||
signatureVisitor, | ||
annotationVisitor, | ||
fieldVisitor, | ||
methodVisitor, | ||
resultCollector | ||
); | ||
|
||
reader.accept(defaultClassVisitor, 0); | ||
|
||
// Confirms that after analyzing there were no annotations in the test class. | ||
Assertions.assertEquals(0, ClassMembersVisitorCounter.getNbVisitedAnnotations()); | ||
|
||
// Confirms that after analyzing there was only 1 field in the test class. | ||
Assertions.assertEquals(1, ClassMembersVisitorCounter.getNbVisitedFields()); | ||
|
||
// Confirms that after analyzing there were 3 methods in the test class. | ||
Assertions.assertEquals(3, ClassMembersVisitorCounter.getNbVisitedMethods()); | ||
|
||
// Confirms that after analyzing there was only 1 type in the test class. | ||
Assertions.assertEquals(1, ClassMembersVisitorCounter.getNbVisitedTypes()); | ||
|
||
// Confirms that the result of analyzed data has been collected successfully. | ||
Assertions.assertFalse(resultCollector.getDependencies().isEmpty()); | ||
} | ||
} |
Binary file added
BIN
+1016 Bytes
depclean-core/src/test/resources/ClassFileVisitorResources/ExampleClass.class
Binary file not shown.