Reputation: 2006
I want to write a unit test that starts the test when a message is received at my GcmListenerService
,I tried to bind to the the GcmListenerService
but it is not possible because GcmListenerService
overrides onBind
with such that the method can't be overridden.
starting the service from my test doesn't make sense because I want it bo be invoked when a message is received from the server.
any ideas ?
Upvotes: 0
Views: 361
Reputation: 2006
I have found a solution by creating a GCMListenerService
object,I hope this is the right way.
public class mytest{
private GCMListenerService mReceiver;
private Context context;
@Before
public void init() {
context = InstrumentationRegistry.getTargetContext();
mReceiver=new GCMListenerService(context);
}
@Test
public void testGPS() {
Bundle bundle = new Bundle();
bundle.putString("message", Constants.GET_LOCATION);
mReceiver.onMessageReceived("maxim",bundle);
}
}
Upvotes: 2