Skip to content

Commit

Permalink
Add tests for the parse and compare hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
olmokramer committed Oct 3, 2023
1 parent a6f810b commit 55624bd
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions core/src/test/java/de/jplag/HooksTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 55624bd

Please sign in to comment.