Commit 1b893f3b authored by Bergamote Orange's avatar Bergamote Orange
Browse files

MR comments, improve unit tests

parent a128a396
......@@ -9,6 +9,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
......@@ -21,14 +22,15 @@ class VisitsInSameCounterTest {
@Mock
private DecodedVisit decodedVisit;
private static final Duration exposureTimeUnit = Duration.ofSeconds(1800);
@Test
void incrementIfScannedInSameTimeUnitThanLastScanTime_increments_counter_when_difference_between_scan_time_is_lower_than_exposureTimeUnit() {
final long exposureTimeUnit = 1800L;
final VisitsInSameUnitCounter counter = new VisitsInSameUnitCounter(exposureTimeUnit);
final VisitsInSameUnitCounter counter = new VisitsInSameUnitCounter(exposureTimeUnit.getSeconds());
final int initialCount = 0;
counter.setCount(initialCount);
final Instant lastScanTime = Instant.now().minusMillis(exposureTimeUnit - 1000);
final Instant lastScanTime = Instant.now().minus(exposureTimeUnit.minus(1, ChronoUnit.SECONDS));
// 1s after
final Instant currentVisitScanTime = Instant.now();
counter.setLastScanTime(lastScanTime);
......@@ -41,13 +43,11 @@ class VisitsInSameCounterTest {
@Test
void incrementIfScannedInSameTimeUnitThanLastScanTime_does_not_increment_counter_when_difference_between_scan_time_is_greater_than_exposureTimeUnit() {
final long exposureTimeUnit = 1800L;
final VisitsInSameUnitCounter counter = new VisitsInSameUnitCounter(exposureTimeUnit);
final VisitsInSameUnitCounter counter = new VisitsInSameUnitCounter(exposureTimeUnit.getSeconds());
final int initialCount = 0;
counter.setCount(initialCount);
final Instant lastScanTime = Instant.now().minus(exposureTimeUnit + 1000, ChronoUnit.SECONDS);
// 1s after
final Instant lastScanTime = Instant.now().minus(exposureTimeUnit.plus(1, ChronoUnit.SECONDS));
final Instant currentVisitScanTime = Instant.now();
counter.setLastScanTime(lastScanTime);
when(decodedVisit.getQrCodeScanTime()).thenReturn(currentVisitScanTime);
......@@ -56,4 +56,19 @@ class VisitsInSameCounterTest {
Assertions.assertThat(counter.getCount()).isEqualTo(initialCount);
}
@Test
void incrementIfScannedInSameTimeUnitThanLastScanTime_does_not_increment_counter_when_no_lastScanTime_has_already_been_registered() {
final VisitsInSameUnitCounter counter = new VisitsInSameUnitCounter(exposureTimeUnit.getSeconds());
final int initialCount = 0;
counter.setCount(initialCount);
final Instant currentVisitScanTime = Instant.now();
when(decodedVisit.getQrCodeScanTime()).thenReturn(currentVisitScanTime);
counter.incrementIfScannedInSameTimeUnitThanLastScanTime(decodedVisit);
Assertions.assertThat(counter.getLastScanTime()).isEqualTo(currentVisitScanTime);
Assertions.assertThat(counter.getCount()).isEqualTo(initialCount);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment