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

Fix NPE on basecode run with empty submission folder.

Alberth 4 лет назад
Родитель
Сommit
9cbfaae0e0

+ 2 - 0
jplag/src/main/java/de/jplag/Submission.java

@@ -155,6 +155,8 @@ public class Submission implements Comparable<Submission> {
     public boolean parse(boolean debugParser) {
         if (files == null || files.size() == 0) {
             errorCollector.print("ERROR: nothing to parse for submission \"" + name, null);
+            tokenList = null;
+            hasErrors = true; // invalidate submission
             return false;
         }
 

+ 6 - 0
jplag/src/test/java/de/jplag/BaseCodeTest.java

@@ -14,6 +14,12 @@ public class BaseCodeTest extends TestBase {
         verifyResults(result);
     }
 
+    @Test
+    public void testEmptySubmission() throws ExitException {
+        JPlagResult result = runJPlag("emptysubmission", it -> it.setBaseCodeSubmissionName("base"));
+        verifyResults(result);
+    }
+
     @Test
     public void testAutoTrimFileSeparators() throws ExitException {
         JPlagResult result = runJPlag("basecode", it -> it.setBaseCodeSubmissionName(File.separator + "base" + File.separator));

+ 27 - 0
jplag/src/test/resources/de/jplag/samples/emptysubmission/A/TerrainType.java

@@ -0,0 +1,27 @@
+package carcassonne.model.terrain;
+
+import java.util.List;
+
+/**
+ * Enumeration for the terrain type. Is used to specify the terrain of a tile on its different positions.
+ * @author Timur Saglam
+ */
+public enum TerrainType {
+    CASTLE,
+    ROAD,
+    MONASTERY,
+    FIELDS,
+    OTHER;
+
+    /**
+     * Generates a list of the basic terrain types, which is every terrain except {@link Other}.
+     * @return a list of CASTLE, ROAD, MONASTERY, FIELDS.
+     */
+    public static List<TerrainType> basicTerrain() {
+        return List.of(CASTLE, ROAD, MONASTERY, FIELDS);
+    }
+
+    public String toReadableString() {
+        return toString().charAt(0) + toString().substring(1).toLowerCase();
+    }
+}

+ 30 - 0
jplag/src/test/resources/de/jplag/samples/emptysubmission/B/TerrainType.java

@@ -0,0 +1,30 @@
+package carcassonne.model.terrain;
+
+import java.util.List;
+
+/**
+ * Enumeration for the terrain type. Is used to specify the terrain of a tile on its different positions.
+ * @author Mean Plagiarizer
+ */
+public enum TerrainType {
+    CASTLE,
+    ROAD,
+    MONASTERY,
+    FIELDS,
+    OTHER;
+
+    private static final int CONST_0 = 0;
+    private static final int CONST_1 = 1;
+
+    /**
+     * Generates a list of the basic terrain types, which is every terrain except {@link Other}.
+     * @return a list of CASTLE, ROAD, MONASTERY, FIELDS.
+     */
+    public static List<TerrainType> basicTerrain() {
+        return List.of(CASTLE, ROAD, MONASTERY, FIELDS);
+    }
+
+    public String toReadableString() {
+        return toString().charAt(CONST_0) + toString().substring(CONST_1).toLowerCase();
+    }
+}

+ 12 - 0
jplag/src/test/resources/de/jplag/samples/emptysubmission/base/TerrainType.java

@@ -0,0 +1,12 @@
+package carcassonne.model.terrain;
+
+/**
+ * Enumeration for the terrain type. Is used to specify the terrain of a tile on its different positions.
+ */
+public enum TerrainType {
+    CASTLE,
+    ROAD,
+    MONASTERY,
+    FIELDS,
+    OTHER;
+}

+ 1 - 0
jplag/src/test/resources/de/jplag/samples/emptysubmission/empty/not_a_source.file

@@ -0,0 +1 @@
+Non-source file