Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 0a9cb58

Browse files
Stefan KockStefanKock
authored andcommitted
SORMAS-Foundation#3818: Replace mocked Consumer with a dummy implementation
- Avoids NPE on Github CI when using the mock instance the first time
1 parent 3edc4e8 commit 0a9cb58

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

sormas-backend/src/test/java/de/symeda/sormas/backend/util/IterableHelperTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package de.symeda.sormas.backend.util;
22

3-
import static org.mockito.Matchers.anyList;
4-
import static org.mockito.Mockito.mock;
5-
import static org.mockito.Mockito.times;
6-
import static org.mockito.Mockito.verify;
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
75

86
import java.util.Arrays;
97
import java.util.List;
@@ -38,12 +36,22 @@ public void testExecuteBatched() {
3836
assertExecuteCount(5, 2, 1, 2, 3, 4, 5, 6);
3937
}
4038

41-
@SuppressWarnings("unchecked")
4239
private static void assertExecuteCount(int batchSize, int executions, Integer... entries) {
4340

44-
Consumer<List<Integer>> batchFunction = mock(Consumer.class);
41+
// Workaround instead of mocking because the mocked instance resulted in an NPE on Github CI.
42+
CountCalls<Integer> batchFunction = new CountCalls<>();
4543

4644
IterableHelper.executeBatched(Arrays.asList(entries), batchSize, batchFunction);
47-
verify(batchFunction, times(executions)).accept(anyList());
45+
assertThat(batchFunction.counter, equalTo(executions));
46+
}
47+
48+
private static class CountCalls<E> implements Consumer<List<E>> {
49+
50+
private int counter;
51+
52+
@Override
53+
public void accept(List<E> t) {
54+
counter++;
55+
}
4856
}
4957
}

0 commit comments

Comments
 (0)