Closed GoogleCodeExporter closed 8 years ago
Original comment by nkors...@google.com
on 5 May 2015 at 5:26
Original comment by slinz...@google.com
on 15 Sep 2015 at 10:58
I can successfully capture and test Intents sent with startActivity() but the
same intent and same intended() matchers fail for one sent with sendBroadcast()
or through LocalBroadcastManager.
Original comment by neil.mac...@mobileforming.com
on 19 Sep 2015 at 1:20
I have recently used mockito to test localbroadcastmanager..
1. Create a argument matcher for Intent
public static class ReSync extends ArgumentMatcher<Intent> {
@Override
public boolean matches(Object intent) {
return ((Intent) intent).getAction().equals(Constants.INTENT_RESYNC);
}
@Override
public String toString() {
return "Intent Action Constants.INTENT_RESYNC";
}
}
2. Mock the localbroadcastmanager
LocalBroadcastManager localBroadcastManager = Mockito.mock(LocalBroadcastManager.class);
3. verify the method was called with the intent.
Mockito.verify(localBroadcastManager).sendBroadcast(argThat(new IntentMatchers.StartWorking()));
Mockito.verify(localBroadcastManager).sendBroadcast(argThat(new IntentMatchers.ShowsSynced()));
Mockito.verify(localBroadcastManager).sendBroadcast(argThat(new IntentMatchers.StopWorking()));
You have to remember to pass in your mocked localbroadcastmanager instance to
the method being tested!
Original comment by mat...@winters.org.nz
on 19 Sep 2015 at 2:25
This WAI. Espresso Intents does only support Intent stubbing and verification
for Activities. Any other components would require a new framework APIs.
Original comment by slinz...@google.com
on 23 Sep 2015 at 9:49
Why won't fix? Those components are just as necessary to test as Activity
Intents. I understand it would take new framework APIs for the hooks, but,
only putting those hooks in for Activity Intents seems incomplete.
Either way, the naming and documentation of EspressoIntents and IntentsTestRule
don't do a very good job at describing to developers that these can ONLY be
used for Activity Intents. At the very least it should note in the docs that
this does NOT work for sendBroadcast() or startService(), etc.
Original comment by neil.mac...@mobileforming.com
on 23 Sep 2015 at 10:10
Original issue reported on code.google.com by
mat...@winters.org.nz
on 4 May 2015 at 2:32