|
|
@@ -3,6 +3,8 @@ package jplag.endToEndTesting;
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
@@ -15,18 +17,25 @@ import de.jplag.JPlagComparison;
|
|
|
import de.jplag.JPlagResult;
|
|
|
import de.jplag.endToEndTesting.constants.Constant;
|
|
|
import de.jplag.endToEndTesting.helper.JPlagTestSuiteHelper;
|
|
|
+import de.jplag.endToEndTesting.model.TestCaseModel;
|
|
|
+import de.jplag.exceptions.ExitException;
|
|
|
import de.jplag.options.LanguageOption;
|
|
|
|
|
|
-import model.TestCaseModel;
|
|
|
-
|
|
|
+/**
|
|
|
+ * Main test class for end-to-end testing in the Java language. The test cases
|
|
|
+ * aim to detect changes in the detection of plagiarism in the Java language and
|
|
|
+ * to be able to roughly categorize them. The plagiarism is compared with the
|
|
|
+ * original class. The results are compared with the results from previous tests
|
|
|
+ * and changes are detected.
|
|
|
+ */
|
|
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
|
class javaTestCases {
|
|
|
private static final Logger logger = LoggerFactory.getLogger("EndToEndTesting");
|
|
|
-
|
|
|
+
|
|
|
private JPlagTestSuiteHelper jplagTestSuiteHelper;
|
|
|
|
|
|
@BeforeAll
|
|
|
- public void setUp() throws Exception {
|
|
|
+ public void setUp() throws IOException {
|
|
|
jplagTestSuiteHelper = new JPlagTestSuiteHelper(LanguageOption.JAVA);
|
|
|
assertTrue(Constant.BASE_PATH_TO_JAVA_RESOURCES_SORTALGO.toFile().exists(), "Could not find base directory!");
|
|
|
assertTrue(Constant.BASE_PATH_TO_JAVA_RESULT_JSON.toFile().exists(),
|
|
|
@@ -34,7 +43,7 @@ class javaTestCases {
|
|
|
}
|
|
|
|
|
|
@AfterEach
|
|
|
- public void teardown() throws Exception {
|
|
|
+ public void teardown() {
|
|
|
// after close the created directories are deleted
|
|
|
jplagTestSuiteHelper.clear();
|
|
|
}
|
|
|
@@ -42,32 +51,39 @@ class javaTestCases {
|
|
|
/**
|
|
|
* Inserting comments or empty lines (normalization level)
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void normalizationLevelTestOne() throws Exception {
|
|
|
+ void normalizationLevelTestOne() throws IOException, ExitException {
|
|
|
|
|
|
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo1.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
-
|
|
|
+
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Changing variable names or function names (normalization level)
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void normalizationLevelTestTwo() throws Exception {
|
|
|
+ void normalizationLevelTestTwo() throws IOException, ExitException {
|
|
|
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo2.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
@@ -75,20 +91,24 @@ class javaTestCases {
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Inserting comments or empty lines (normalization level)
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void normalizationLevelTestThree() throws Exception {
|
|
|
+ void normalizationLevelTestThree() throws IOException, ExitException {
|
|
|
String[] testClassNames = new String[] { "SortAlgo1.java", "SortAlgo2.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
@@ -96,20 +116,24 @@ class javaTestCases {
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Insertion of unnecessary or changed code lines (token generation)
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void tokenGenerationLevelTestOne() throws Exception {
|
|
|
+ void tokenGenerationLevelTestOne() throws IOException, ExitException {
|
|
|
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo3.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
@@ -117,21 +141,25 @@ class javaTestCases {
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Changing the program flow (token generation) (statements and functions must be
|
|
|
- * independent from each other)
|
|
|
+ * Changing the program flow (token generation) (statements and functions must
|
|
|
+ * be independent from each other)
|
|
|
*
|
|
|
- * @throws Exception
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void tokenGenerationLevelTestTwo() throws Exception {
|
|
|
+ void tokenGenerationLevelTestTwo() throws IOException, ExitException {
|
|
|
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
@@ -139,20 +167,25 @@ class javaTestCases {
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Variable declaration at the beginning of the program (Detecting Source Code
|
|
|
* Plagiarism [...])
|
|
|
- * @throws Exception
|
|
|
+ *
|
|
|
+ * @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.
|
|
|
*/
|
|
|
@Test
|
|
|
- void tokenGenerationLevelTestThree() throws Exception {
|
|
|
+ void tokenGenerationLevelTestThree() throws IOException, ExitException {
|
|
|
String[] testClassNames = new String[] { "SortAlgo.java", "SortAlgo4d1.java" };
|
|
|
|
|
|
TestCaseModel testCaseModel = jplagTestSuiteHelper.createNewTestCase(testClassNames);
|
|
|
@@ -160,10 +193,11 @@ class javaTestCases {
|
|
|
JPlagResult jplagResult = new JPlag(testCaseModel.getJPlagOptionsFromCurrentModel()).run();
|
|
|
|
|
|
var resultJsonModel = testCaseModel.getCurrentResultJsonModel();
|
|
|
-
|
|
|
+
|
|
|
for (JPlagComparison jPlagComparison : jplagResult.getAllComparisons()) {
|
|
|
logger.info("Comparison of the stored values and the current equality values");
|
|
|
- assertEquals( resultJsonModel.similarity(), jPlagComparison.similarity() , "The JPlag results [similarity] do not match the stored values!");
|
|
|
+ assertEquals(resultJsonModel.similarity(), jPlagComparison.similarity(),
|
|
|
+ "The JPlag results [similarity] do not match the stored values!");
|
|
|
}
|
|
|
}
|
|
|
}
|