From 640e1fa8d5db5d3eb4e46c83b453c34a81181cae Mon Sep 17 00:00:00 2001 From: Robin Maisch Date: Mon, 18 Mar 2024 21:00:40 +0100 Subject: [PATCH] Fix tests --- languages/java-cpg/pom.xml | 47 +++++++------------ .../java/de/jplag/java_cpg/MatchingTest.java | 6 +-- .../transform/PlagiarismDetectionTest.java | 20 ++++---- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/languages/java-cpg/pom.xml b/languages/java-cpg/pom.xml index e573d5e73..52e5f0ea3 100644 --- a/languages/java-cpg/pom.xml +++ b/languages/java-cpg/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 de.jplag @@ -17,13 +15,19 @@ 1.9.0 - ${cpg.groupId} cpg-core ${cpg.version} + + + + org.apache.logging.log4j + log4j-slf4j2-impl + + ${cpg.groupId} @@ -35,11 +39,6 @@ cpg-analysis ${cpg.version} - - ${cpg.groupId} - cpg-neo4j - ${cpg.version} - org.jetbrains.kotlin kotlin-stdlib-jdk8 @@ -51,52 +50,38 @@ ${kotlin.version} test - - de.jplag - jplag - ${revision} - test - - - - jitpack.io - https://jitpack.io - - - org.jetbrains.kotlin kotlin-maven-plugin ${kotlin.version} + + 1.8 + + -Xcontext-receivers + + compile - process-sources compile + process-sources test-compile - test-compile test-compile + test-compile - - 1.8 - - -Xcontext-receivers - - - diff --git a/languages/java-cpg/src/test/java/de/jplag/java_cpg/MatchingTest.java b/languages/java-cpg/src/test/java/de/jplag/java_cpg/MatchingTest.java index c7c8ea2ff..7b00cca76 100644 --- a/languages/java-cpg/src/test/java/de/jplag/java_cpg/MatchingTest.java +++ b/languages/java-cpg/src/test/java/de/jplag/java_cpg/MatchingTest.java @@ -19,7 +19,6 @@ import de.jplag.ParsingException; import de.jplag.java_cpg.transformation.matching.CpgIsomorphismDetector; import de.jplag.java_cpg.transformation.matching.PatternRepository; -import de.jplag.java_cpg.transformation.matching.pattern.GraphPatternBuilder; import de.jplag.java_cpg.transformation.matching.pattern.Match; import de.jplag.java_cpg.transformation.matching.pattern.SimpleGraphPattern; @@ -34,7 +33,7 @@ public static Stream providePairs() { @ParameterizedTest @MethodSource("providePairs") - public void testMatch(String filename, Class rootType, GraphPatternBuilder builder) { + public void testMatch(String filename, Class rootType, SimpleGraphPattern pattern) { File file = new File(baseDirectory, filename); try { CpgAdapter cpgAdapter = new CpgAdapter(); @@ -44,9 +43,8 @@ public void testMatch(String filename, Class rootType, Graph detector.loadGraph(graph); List rootCandidates = detector.getNodesOfType(rootType); - SimpleGraphPattern pattern1 = (SimpleGraphPattern) builder.build(); Assertions.assertTrue(rootCandidates.stream().anyMatch(candidate -> { - List matches = pattern1.recursiveMatch(candidate); + List matches = pattern.recursiveMatch(candidate); if (matches.isEmpty()) { return false; } diff --git a/languages/java-cpg/src/test/java/de/jplag/java_cpg/transform/PlagiarismDetectionTest.java b/languages/java-cpg/src/test/java/de/jplag/java_cpg/transform/PlagiarismDetectionTest.java index 6c1f2bcd9..bf0acdd3d 100644 --- a/languages/java-cpg/src/test/java/de/jplag/java_cpg/transform/PlagiarismDetectionTest.java +++ b/languages/java-cpg/src/test/java/de/jplag/java_cpg/transform/PlagiarismDetectionTest.java @@ -1,5 +1,7 @@ package de.jplag.java_cpg.transform; +import static de.jplag.java_cpg.transformation.TransformationRepository.*; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -22,7 +24,6 @@ import de.jplag.Token; import de.jplag.java_cpg.JavaCpgLanguage; import de.jplag.java_cpg.transformation.GraphTransformation; -import de.jplag.java_cpg.transformation.TransformationRepository; /** * An integration test that checks whether pairs of submissions are accepted as equal after being subjected to different @@ -41,14 +42,15 @@ public static void setUpOnce() { } private static Stream getArguments() { - return Stream.of(Arguments.of("singleUseVariable", new GraphTransformation[] {TransformationRepository.inlineSingleUseVariable}), - Arguments.of("constantClass", new GraphTransformation[] {TransformationRepository.moveConstantToOnlyUsingClass}), - Arguments.of("for2While", new GraphTransformation[] {TransformationRepository.forStatementToWhileStatement}), - Arguments.of("negatedIf", new GraphTransformation[] {TransformationRepository.ifWithNegatedConditionResolution}), - Arguments.of("unusedVariables", - new GraphTransformation[] {TransformationRepository.removeUnusedVariableDeclarationStatement, - TransformationRepository.removeUnusedVariableDeclaration, TransformationRepository.removeEmptyDeclarationStatement}), - Arguments.of("dfgLinearization", new GraphTransformation[] {})); + return Stream + .of(Arguments.of("singleUseVariable", new GraphTransformation[] {inlineSingleUseVariable}), + Arguments.of("constantClass", + new GraphTransformation[] {moveConstantToOnlyUsingClass, removeLibraryRecord, removeLibraryField}), + Arguments.of("for2While", new GraphTransformation[] {forStatementToWhileStatement}), + Arguments.of("negatedIf", new GraphTransformation[] {ifWithNegatedConditionResolution}), + Arguments.of("unusedVariables", new GraphTransformation[] {removeUnusedVariableDeclarationStatement, + removeUnusedVariableDeclaration, removeEmptyDeclarationStatement}), + Arguments.of("dfgLinearization", new GraphTransformation[] {})); } @ParameterizedTest