Просмотр исходного кода

Adapt Java feature test and the test base to allow exclusion files.

Timur Sağlam 5 лет назад
Родитель
Сommit
b8c746c29e

+ 4 - 3
jplag/src/test/java/jplag/NewJavaFeaturesTest.java

@@ -5,11 +5,12 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 
 public class NewJavaFeaturesTest extends TestBase {
+    private static final String EXCLUSION_FILE_NAME = "blacklist.txt";
     private static final String ROOT_DIRECTORY = "NewJavaFeatures";
 
     @Test
-    public void testSimpleDuplicate() throws ExitException {
-        JPlagResult result = runJPlagWithDefaultOptions(ROOT_DIRECTORY);
+    public void testJavaFeatureDuplicates() throws ExitException {
+        JPlagResult result = runJPlagWithExclusionFile(ROOT_DIRECTORY, EXCLUSION_FILE_NAME);
         
         // Two submissions, one comparison with 100% match:
         assertEquals(2, result.getNumberOfSubmissions());
@@ -18,7 +19,7 @@ public class NewJavaFeaturesTest extends TestBase {
         assertEquals(100, comparison.percent(), Double.MIN_NORMAL);
         
         // Five matches that each start at the same position:
-        assertEquals(5, comparison.matches.size());
+        assertEquals(4, comparison.matches.size());
         for (Match match : comparison.matches) {
             assertEquals(match.startA, match.startB);
         }

+ 15 - 3
jplag/src/test/java/jplag/TestBase.java

@@ -1,15 +1,27 @@
 package jplag;
 
+import java.util.function.Consumer;
+
 import jplag.options.JPlagOptions;
 import jplag.options.LanguageOption;
 
 public abstract class TestBase {
 
+    private static final String BASE_PATH = "src/test/resources/samples";
+
+    protected JPlagResult runJPlagWithExclusionFile(String testSampleName, String exclusionFileName) throws ExitException {
+        String blackList = String.format(BASE_PATH + "/%s/%s", testSampleName, exclusionFileName);
+        return runJPlagWithOptions(testSampleName, options -> options.setExclusionFileName(blackList));
+    }
+
     protected JPlagResult runJPlagWithDefaultOptions(String testSampleName) throws ExitException {
-        JPlagOptions options = new JPlagOptions(
-                String.format("src/test/resources/samples/%s", testSampleName),
-                LanguageOption.JAVA_1_9);
+        return runJPlagWithOptions(testSampleName, options -> {});
+    }
+
+    protected JPlagResult runJPlagWithOptions(String testSampleName, Consumer<JPlagOptions> customization) throws ExitException {
+        JPlagOptions options = new JPlagOptions(String.format(BASE_PATH + "/%s", testSampleName), LanguageOption.JAVA_1_9);
         options.setDebugParser(true);
+        customization.accept(options);
         JPlag jplag = new JPlag(options);
         return jplag.run();
     }