Skip to content

Commit 08a05b1

Browse files
committed
test: add test on exception being thrown
1 parent ef9f82b commit 08a05b1

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/test/java/uk/gov/di/ipv/cri/common/library/util/EventProbeTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static org.junit.jupiter.api.Assertions.assertSame;
3131
import static org.junit.jupiter.api.Assertions.assertTrue;
3232
import static org.mockito.ArgumentMatchers.any;
33+
import static org.mockito.Mockito.doThrow;
3334
import static org.mockito.Mockito.never;
3435
import static org.mockito.Mockito.verify;
3536

@@ -242,4 +243,24 @@ void shouldFallbackOnBadMetric() {
242243
assertDoesNotThrow(() -> eventProbe.counterMetric("with space"));
243244
assertDoesNotThrow(() -> eventProbe.counterMetric("with space", 1d));
244245
}
246+
247+
@Test
248+
void counterMetricHandlesExceptionGracefully() {
249+
doThrow(new RuntimeException("error")).when(mockMetrics).addMetric("bad metric", 1d);
250+
251+
EventProbe result = assertDoesNotThrow(() -> eventProbe.counterMetric("bad-metric"));
252+
253+
verify(mockMetrics).addMetric("bad-metric", 1d);
254+
assertSame(eventProbe, result);
255+
}
256+
257+
@Test
258+
void counterMetricWithValueHandlesExceptionGracefully() {
259+
doThrow(new RuntimeException("error")).when(mockMetrics).addMetric("bad-metric-2", 42d);
260+
261+
EventProbe result = assertDoesNotThrow(() -> eventProbe.counterMetric("bad-metric-2", 42d));
262+
263+
verify(mockMetrics).addMetric("bad-metric-2", 42d);
264+
assertSame(eventProbe, result);
265+
}
245266
}

0 commit comments

Comments
 (0)