I am trying to verify that specific extras are added to Intent, but all the time I get null for the Intent in Unit test Android. I have the following class that need to be test:
public class TestClass extends SomeNotifier {
private Intent mIntent = new Intent("testintent");
public TestClassConstructor(Context context) {
super(context);
}
@Override
public void notifyChange() {
mIntent.putExtra("Key one", 22);
mIntent.putExtra("Key two", 23);
mIntent.putExtra("Key three", 24);
getContext().sendBroadcast(mIntent);
}
}
And the test is the following (I tried with mockIntent as well, but the result is the same, again the extras are null):
@RunWith(MockitoJUnitRunner.class)
public class TestClassTest {
@Mock
Context mMockContext;
@Test
public void sendBroadcastTest() {
ArgumentCaptor<Intent> argument = ArgumentCaptor.forClass(Intent.class);
TestClass testClassNotifier = new TestClass (mMockContext);
testClassNotifier.notifyChange();
verify(mMockContext).sendBroadcast(argument.capture());
Intent intent = argument.getValue();
//THE INTENT IS NULL
Assert.assertTrue(intent.hasExtra("Key one"));
}
}
Do you have any suggestion how should I make this test to work? Thanks in advance