Explorar el Código

removed duplicate code in the test cases.

Patrick Thiel hace 4 años
padre
commit
20dbb1c81a

+ 1 - 2
jplag.endToEndTesting/src/main/java/de/jplag/end_to_end_testing/helper/JPlagTestSuiteHelper.java

@@ -53,9 +53,8 @@ public class JPlagTestSuiteHelper {
      * @return comparison results saved for the test
      * @throws IOException Exception can be thrown in cases that involve reading, copying or locating files.
      */
-    public TestCaseModel createNewTestCase(String[] classNames) throws IOException {
+    public TestCaseModel createNewTestCase(String[] classNames, String functionName) throws IOException {
         createNewTestCaseDirectory(classNames);
-        var functionName = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get()).getMethodName();
         JsonModel resultJsonModel = resultModel.stream().filter(jsonModel -> functionName.equals(jsonModel.getFunctionName())).findAny().orElse(null);
         return new TestCaseModel(Constant.TEMPORARY_SUBMISSION_DIRECTORY_NAME, resultJsonModel, languageOption);
     }

+ 3 - 3
jplag.endToEndTesting/src/main/java/de/jplag/end_to_end_testing/model/ResultModel.java

@@ -11,7 +11,7 @@ public class ResultModel {
     @JsonProperty("result_similarity")
     private float resultSimilarity;
     @JsonProperty("test_identifier")
-    private Integer testIdentifier;
+    private int testIdentifier;
 
     /**
      * Constructor for the ResultModel. The model is the serialization of the Json file in the form of a Java object.
@@ -19,7 +19,7 @@ public class ResultModel {
      * @param testIdentifier specifies which associated test results are needed for a test case and are therefore associated
      * with this Id.
      */
-    public ResultModel(float resultSimilarity, Integer testIdentifier) {
+    public ResultModel(float resultSimilarity, int testIdentifier) {
         this.resultSimilarity = resultSimilarity;
         this.testIdentifier = testIdentifier;
     }
@@ -35,7 +35,7 @@ public class ResultModel {
     /**
      * @return Identifier assigned to the result
      */
-    public Integer getTestId() {
+    public int getTestId() {
         return testIdentifier;
     }
 

+ 18 - 20
jplag.endToEndTesting/src/test/java/de/jplag/end_to_end_testing/JavaEndToEndTest.java

@@ -69,24 +69,14 @@ class JavaEndToEndTest {
      * Inserting comments or empty lines (normalization level) -> id = 0 Changing variable names or function names
      * (normalization level) -> id = 1 Inserting comments or empty lines (normalization level) -> id = 2
      * @param testClassNames Plagiarized classes names in the resource directorie which are needed for the test
-     * @param testId name of the testId to load and identify the stored results
+     * @param testIdentifier name of the testId to load and identify the stored results
      * @throws IOException is thrown in case of problems with copying the plagiarism classes
      * @throws ExitException in case the plagiarism detection with JPlag is preemptively terminated would be of the test.
      */
     @ParameterizedTest
     @MethodSource("normalizationLevelTestArguments")
-    void normalizationLevelTest(String[] testClassNames, int testId) throws IOException, ExitException {
-
-        TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
-
-        JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
-
-        var jsonModel = testCaseModel.getCurrentJsonModel();
-
-        for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
-            assertEquals(jsonModel.getResultModelById(testId).getResultSimilarity(), jPlagComparison.similarity(),
-                    "The JPlag results [similarity] do not match the stored values!");
-        }
+    void normalizationLevelTest(String[] testClassNames, int testIdentifier) throws IOException, ExitException {
+        runJPlagTestSuite(testClassNames, testIdentifier);
     }
 
     /**
@@ -94,22 +84,30 @@ class JavaEndToEndTest {
      * generation) (statements and functions must be independent from each other) -> id = 1 Variable declaration at the
      * beginning of the program (Detecting Source Code Plagiarism [...]) -> id = 2
      * @param testClassNames Plagiarized classes names in the resource directorie which are needed for the test
-     * @param testId name of the testId to load and identify the stored results
+     * @param testIdentifier name of the testId to load and identify the stored results
      * @throws IOException is thrown in case of problems with copying the plagiarism classes
      * @throws ExitException in case the plagiarism detection with JPlag is preemptively terminated would be of the test.
      */
     @ParameterizedTest
     @MethodSource("tokenGenerationLevelTestArguments")
-    void tokenGenerationLevelTest(String[] testClassNames, int testId) throws IOException, ExitException {
-
-        TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
+    void tokenGenerationLevelTest(String[] testClassNames, int testIdentifier) throws IOException, ExitException {
+        runJPlagTestSuite(testClassNames, testIdentifier);
+    }
 
+    /**
+     * This method creates the necessary results as well as models for a test run and summarizes them for a comparison.
+     * @param testClassNames Plagiarized classes names in the resource directorie which are needed for the test
+     * @param testIdentifier name of the testId to load and identify the stored results
+     * @throws IOException is thrown in case of problems with copying the plagiarism classes
+     * @throws ExitException in case the plagiarism detection with JPlag is preemptively terminated would be of the test.
+     */
+    private void runJPlagTestSuite(String[] testClassNames, int testIdentifier) throws IOException, ExitException {
+        String functionName = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get()).getMethodName();
+        TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames, functionName);
         JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
 
-        var jsonModel = testCaseModel.getCurrentJsonModel();
-
         for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
-            assertEquals(jsonModel.getResultModelById(testId).getResultSimilarity(), jPlagComparison.similarity(),
+            assertEquals(testCaseModel.getCurrentJsonModel().getResultModelById(testIdentifier).getResultSimilarity(), jPlagComparison.similarity(),
                     "The JPlag results [similarity] do not match the stored values!");
         }
     }