My EasyMock's expected method is perceived as unexpected, although I do not use and strict mocks, and the method is already declared before being replied.
Test fails in this line of code:
Intent batteryIntent = context.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Test:
@Before
public void setUp() {
mocksControl = createControl();
contextMock = mocksControl.createMock(Context.class);
//(...)
}
@Test
public void test() {
expect(contextMock.getApplicationContext()).andReturn(contextMock).anyTimes();
expect(contextMock.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)))
.andReturn(someIntent1).once();
expect(contextMock.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)))
.andReturn(someIntent2).once();
mocksControl.replay();
//(...) tested method is invoked on class under the test
}
Error I get:
java.lang.AssertionError:
Unexpected method call Context.registerReceiver(null, android.content.IntentFilter@c009614f):
Context.registerReceiver(null, android.content.IntentFilter@c009614f): expected: 1, actual: 0
Context.registerReceiver(null, android.content.IntentFilter@c009614f): expected: 1, actual: 0