File tree Expand file tree Collapse file tree
src/test/java/uk/gov/di/ipv/cri/common/library/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030import static org .junit .jupiter .api .Assertions .assertSame ;
3131import static org .junit .jupiter .api .Assertions .assertTrue ;
3232import static org .mockito .ArgumentMatchers .any ;
33+ import static org .mockito .Mockito .doThrow ;
3334import static org .mockito .Mockito .never ;
3435import 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}
You can’t perform that action at this time.
0 commit comments