I have implemented Micrometer Prometheus counter in my service by injecting MeterRegistry
and incrementing the count as shown below, and I have written a test case as well, but when I am running the test case, I am getting:
"java.lang.NullPointerException: Cannot invoke "io.micrometer.core.instrument.MeterRegistry.counter(String, String[])" because "this.meterRegistry" is null".
Service file:
@Autowired
private MeterRegistry meterRegistry;
public void counterIncrement() {
meterRegistry.counter("test_count").increment();
}
Test case file:
@MockBean
private MeterRegistry registry;
@Test
void testCounter() {
// invoking counterIncrement();
}