Skip to content

Commit

Permalink
Merge pull request #105 from ABHAY0O7/class-analyzer-test
Browse files Browse the repository at this point in the history
Class analyzer test
  • Loading branch information
tdurieux authored Aug 20, 2021
2 parents 3336346 + 0f2a3bc commit 063572c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@Slf4j
class CollectorClassFileVisitorTest {

private static final File classFile = new File("src/test/resources/ClassFileVisitorResources/test.class");
private static final File classFile = new File(
"src/test/resources/analysisResources/test.class");
private static final String className = "test";
private static final CollectorClassFileVisitor collector = new CollectorClassFileVisitor();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package se.kth.depclean.core.analysis;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class DefaultClassAnalyzerTest {

// This jar file only contains "ExampleClass.class"
File jarFile = new File("src/test/resources/analysisResources/ExampleClass.jar");
File directoryFile = new File("src/test/resources/asmAndGraphResources");

@Test
@DisplayName("Test that the DCA is accepting a jar and returning its classes successfully.")
void DCA_jar_test() throws IOException {
URL url = jarFile.toURI().toURL();
Assertions.assertFalse(analyze(url));
}

@Test
@DisplayName("Test that the DCA is accepting a directory and returning its classes successfully.")
void DCA_directory_test() throws IOException {
URL url = directoryFile.toURI().toURL();
Assertions.assertFalse(analyze(url));
}

// Utility method to get the classes.
boolean analyze(URL url) throws IOException {
ClassAnalyzer classAnalyzer = new DefaultClassAnalyzer();
return classAnalyzer.analyze(url).isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.kth.depclean.core.analysis;
package se.kth.depclean.core.analysis.asmTest;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -11,7 +11,6 @@
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;
Expand All @@ -20,11 +19,11 @@
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");
private static final File classFile = new File(
"src/test/resources/asmAndGraphResources/ExampleClass.class");

@Test
@DisplayName("Test that the default asm classes are working fine.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package se.kth.depclean.core.analysis;
package se.kth.depclean.core.analysis.graphTest;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -15,7 +15,8 @@
public class DependencyClassFileVisitorTest {

// Resource class for testing.
private static final File classFile = new File("src/test/resources/ClassFileVisitorResources/ExampleClass.class");
private static final File classFile = new File(
"src/test/resources/asmAndGraphResources/ExampleClass.class");
private static final String className = "ExampleClass";

@Test
Expand Down
Binary file not shown.

0 comments on commit 063572c

Please sign in to comment.