Skip to content

Improve error messages for the java language feature test #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions core/src/test/java/de/jplag/NewJavaFeaturesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.jplag.exceptions.ExitException;

public class NewJavaFeaturesTest extends TestBase {

private final Logger logger = LoggerFactory.getLogger(NewJavaFeaturesTest.class);

private static final int EXPECTED_MATCHES = 6; // might change if you add files to the submissions
private static final double EXPECTED_SIMILARITY = 0.96; // might change if you add files to the submissions
private static final String EXPECTED_JAVA_VERSION = "17"; // might change with newer JPlag versions

private static final String EXCLUSION_FILE_NAME = "blacklist.txt";
private static final String ROOT_DIRECTORY = "NewJavaFeatures";
private static final String CHANGE_MESSAGE = "Number of %s changed! If intended, modify the test case!";
private static final String VERSION_MISMATCH_MESSAGE = "Using Java version %s instead of %s may skew the results";
private static final String VERSION_MATCH_MESSAGE = "Java version matches, but results deviate from expected values";
private static final String JAVA_VERSION_KEY = "java.version";

@Test
@DisplayName("test comparison of Java files with modern language features")
public void testJavaFeatureDuplicates() throws ExitException {

JPlagResult result = runJPlagWithExclusionFile(ROOT_DIRECTORY, EXCLUSION_FILE_NAME);

// Ensure test input did not change:
Expand All @@ -29,8 +39,19 @@ public void testJavaFeatureDuplicates() throws ExitException {

// Check similarity and number of matches:
var comparison = result.getAllComparisons().get(0);
assertEquals(EXPECTED_SIMILARITY, comparison.similarity(), DELTA);
assertEquals(EXPECTED_MATCHES, comparison.matches().size());
String versionMessage = createJavaVersionMessage();
assertEquals(EXPECTED_SIMILARITY, comparison.similarity(), DELTA, versionMessage);
assertEquals(EXPECTED_MATCHES, comparison.matches().size(), versionMessage);
}

private String createJavaVersionMessage() {
String actualJavaVersion = System.getProperty(JAVA_VERSION_KEY);
String message = VERSION_MATCH_MESSAGE;
if (!actualJavaVersion.startsWith(EXPECTED_JAVA_VERSION)) {
message = VERSION_MISMATCH_MESSAGE.formatted(actualJavaVersion, EXPECTED_JAVA_VERSION);
logger.error(message);
}
return message;
}

}
4 changes: 3 additions & 1 deletion core/src/test/java/de/jplag/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import de.jplag.clustering.ClusteringOptions;
import de.jplag.exceptions.ExitException;
import de.jplag.java.JavaLanguage;
import de.jplag.options.JPlagOptions;
Expand Down Expand Up @@ -105,7 +106,8 @@ protected JPlagOptions getOptions(List<String> newPaths, Function<JPlagOptions,
protected JPlagOptions getOptions(List<String> newPaths, List<String> oldPaths, Function<JPlagOptions, JPlagOptions> customization) {
var newFiles = newPaths.stream().map(File::new).collect(Collectors.toSet());
var oldFiles = oldPaths.stream().map(File::new).collect(Collectors.toSet());
JPlagOptions options = new JPlagOptions(new JavaLanguage(), newFiles, oldFiles);
JPlagOptions options = new JPlagOptions(new JavaLanguage(), newFiles, oldFiles)
.withClusteringOptions(new ClusteringOptions().withEnabled(false));
return customization.apply(options);
}

Expand Down
11 changes: 8 additions & 3 deletions coverage-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
<artifactId>endtoend-testing</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>language-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>language-antlr-utils</artifactId>
<version>${revision}</version>
</dependency>

<!-- Languages -->
<dependency>
<groupId>de.jplag</groupId>
<artifactId>language-api</artifactId>
<artifactId>language-testutils</artifactId>
<version>${revision}</version>
</dependency>

<!-- Languages -->
<dependency>
<groupId>de.jplag</groupId>
<artifactId>text</artifactId>
Expand Down