From 55624bdc5115a36b73e4ff59b1cd6e20d77d1e2c Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Fri, 15 Sep 2023 14:19:27 +0200 Subject: [PATCH] Add tests for the parse and compare hooks --- core/src/test/java/de/jplag/HooksTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core/src/test/java/de/jplag/HooksTest.java diff --git a/core/src/test/java/de/jplag/HooksTest.java b/core/src/test/java/de/jplag/HooksTest.java new file mode 100644 index 000000000..522774a2f --- /dev/null +++ b/core/src/test/java/de/jplag/HooksTest.java @@ -0,0 +1,53 @@ +package de.jplag; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.jupiter.api.Test; + +import de.jplag.exceptions.ExitException; + +class HooksTest extends TestBase { + private static final String ROOT = "NoDuplicate"; + private static final int SUBMISSION_COUNT = 3; + private static final int COMPARISON_COUNT = 3; + + @Test + void testPreParseHook() throws ExitException { + final AtomicInteger timesCalled = new AtomicInteger(0); + runJPlag(ROOT, it -> it.withPreParseHook(submissions -> { + timesCalled.incrementAndGet(); + assertEquals(SUBMISSION_COUNT, submissions.size()); + })); + assertEquals(1, timesCalled.get()); + } + + @Test + void testParseHook() throws ExitException { + final AtomicInteger totalSubmissions = new AtomicInteger(0); + runJPlag(ROOT, it -> it.withParseHook(submission -> { + totalSubmissions.incrementAndGet(); + })); + assertEquals(SUBMISSION_COUNT, totalSubmissions.get()); + } + + @Test + void testPreCompareHook() throws ExitException { + final AtomicInteger timesCalled = new AtomicInteger(0); + runJPlag(ROOT, it -> it.withPreCompareHook(comparisons -> { + timesCalled.incrementAndGet(); + assertEquals(COMPARISON_COUNT, comparisons.size()); + })); + assertEquals(1, timesCalled.get()); + } + + @Test + void testCompareHook() throws ExitException { + final AtomicInteger totalComparisons = new AtomicInteger(0); + runJPlag(ROOT, it -> it.withCompareHook(comparison -> { + totalComparisons.incrementAndGet(); + })); + assertEquals(COMPARISON_COUNT, totalComparisons.get()); + } +}