package io.github.tobyhs.timetalker;

import android.content.Intent;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ServiceController;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

@RunWith(RobolectricTestRunner.class)
public class ScreenServiceTest {
    @Test
    public void isRunning() {
        ServiceController<ScreenService> controller = Robolectric.buildService(ScreenService.class);
        controller.create();
        assertThat(ScreenService.isRunning(), is(true));

        controller.destroy();
        assertThat(ScreenService.isRunning(), is(false));
    }

    @Test
    public void registersReceiverForScreenOn() {
        Intent intent = new Intent(Intent.ACTION_SCREEN_ON);
        ShadowApplication shadowApp = ShadowApplication.getInstance();

        ServiceController serviceController = Robolectric.buildService(ScreenService.class);
        serviceController.create();
        assertThat(shadowApp.hasReceiverForIntent(intent), is(true));
        serviceController.destroy();
        assertThat(shadowApp.hasReceiverForIntent(intent), is(false));
    }

    @Test
    public void onBind_returnsNull() {
        ScreenService service = new ScreenService();
        assertThat(service.onBind(new Intent()), is(nullValue()));
    }
}

@@ -54,21 +54,87 @@
 content.
-Inten
+BroadcastReceiver;%0Aimport android.content.Intent;%0A%0Aimport java.util.Lis
 t;%0A%0Aimpo
@@ -406,18 +406,112 @@
 atchers.
-is
+hasItem;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.hamcrest.CoreMatchers.isA
 ;%0Aimport
@@ -1328,35 +1328,60 @@
 ();%0A        
-assertThat(
+List%3CBroadcastReceiver%3E receivers = 
 shadowApp.ha
@@ -1374,35 +1374,35 @@
 = shadowApp.
-has
+get
 Receiver
 ForIntent(in
@@ -1381,32 +1381,33 @@
 wApp.getReceiver
+s
 ForIntent(intent
@@ -1407,29 +1407,92 @@
 (intent)
-, is(true
+;%0A        assertThat(receivers, hasItem(isA(ScreenActionReceiver.class)
 ));%0A
+%0A
         

Improve receiver check in ScreenServiceTest