Skip to content

Commit

Permalink
chore: optimized logic of unit test writeCircuitBreakerMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Schnix84 committed Aug 19, 2024
1 parent 9af176f commit af553d3
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Optional;

Expand Down Expand Up @@ -63,10 +64,9 @@ void writeCircuitBreakerMessage() throws JsonCacheException {
// Check if the loop counter is taken from the existing circuit breaker message
assertEquals(circuitBreakerMessage.getLoopCounter(), capturedMessage.getLoopCounter());
// Check if the last opened date is taken from the existing circuit breaker message
long expectedTime = circuitBreakerMessage.getLastOpened().getTime();
long actualTime = capturedMessage.getLastOpened().getTime();
long tolerance = 1000; // 1000 milliseconds tolerance
assertTrue(Math.abs(expectedTime - actualTime) <= tolerance, "Last opened date mismatch");
var expectedTime = Instant.ofEpochMilli(circuitBreakerMessage.getLastOpened().getTime()).truncatedTo(ChronoUnit.SECONDS);
var actualTime = Instant.ofEpochMilli(capturedMessage.getLastOpened().getTime()).truncatedTo(ChronoUnit.SECONDS);
assertEquals(expectedTime, actualTime);
// Check if last modified was updated
assertTrue(capturedMessage.getLastModified().after(testStartDate));
}
Expand Down

0 comments on commit af553d3

Please sign in to comment.