I am not sure why "metric" ends up being null. I want the method to always return the same value for my test
CountMetric countMetric = new CountMetricStub("count");
expect(metricManager.getOrCreateCountMetric(anyObject(String.class))).andStubReturn(countMetric);
CountMetric metric = metricManager.getOrCreateCountMetric("ASDF");
assertNotNull(metric);
any ideas what I am doing wrong here?
thanks, Dean
You need to replay the mock
CountMetric countMetric = new CountMetricStub("count");
expect(metricManager.getOrCreateCountMetric(anyObject(String.class))).andStubReturn(countMetric);
EasyMock.replay(metricManager); //Add this line
CountMetric metric = metricManager.getOrCreateCountMetric("ASDF");
assertNotNull(metric);
Currently, the metricManager is still in record mode which means any calls to its methods just perform default behaviour.
If you have a call to EasyMock.verify() in there too (without the call to replay()) EasyMock tells you that you can't call verify while in record mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With