Reputation: 847
No matter what I do, I get the following error when trying to mock a method
java.lang.IllegalStateException: missing behavior definition for the preceding method call: ConfigurationSection.get("country-language") Usage is: expect(a.foo()).andXXX()
My code for testing:
EasyMock.expect(section.getString("country-language")).andReturn("US");
LocaleManager.updateLocale(section, Collections.emptyList());
EasyMock.expectLastCall();
replayAll();
Assert.assertEquals("Test", TranslatedMessage.translate("test"));
verifyAll();
The expect andReturn is called for the mocked class, and the static upateLocale method calls the method, first thing. The strange thing is this test works fine:
EasyMock.expect(section.getString("country-language")).andReturn("US");
replayAll();
Assert.assertEquals("US", section.getString("country-language"));
verifyAll();
But calling it from an external method doesn't work.
Upvotes: 0
Views: 1285
Reputation: 3915
Your mock says:
EasyMock.expect(section.getString("country-language"))
The error says:
ConfigurationSection.get("country-language")
You are not mocking get("country-language")
. You are mocking getString("country-language")
.
Unrelated, but verify
is a maintenance nightmare and should generally be avoided. This ties test code directly to an implementation. Tests should focus on inputs and outputs if at all possible.
Upvotes: 0