NearbyService extends IntentService { public String getNearbyCode() { return nearbyCode; } NearbyService(); static String[] getRequiredPermissions(); @Override int onStartCommand(@Nullable Intent intent, int flags, int startId); void notify(String message); NearbyState getServiceState(); void setServiceState(NearbyState state, @Nullable String message); static Intent createNearbyIntent(String state, Context context); void handleResponse(boolean error, String message); void handlePayload(Payload payload); void handlePayloadTransferUpdate(PayloadTransferUpdate update); void start(); void stop(); void setNearbyCode(String code); String getNearbyCode(); void sendBroadcastMessage(String message); static final String TAG; static final String ACTION_START; static final String ACTION_STOP; static final String VIDEO_START; }
@Test public void testCodeIntent() { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), TestService.class); intent.putExtra("code", "1234"); intent.setAction(""); controller = Robolectric.buildService(TestService.class, intent); service = controller.create().get(); controller.startCommand(0, 0); assertEquals("1234", service.getNearbyCode()); }
@Test public void testNullActionIntent() { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), TestService.class); intent.putExtra("code", "1234"); controller = Robolectric.buildService(TestService.class, intent); service = controller.create().get(); controller.startCommand(0, 0); assertEquals("1234", service.getNearbyCode()); }