1 package org.robolectric.shadows; 2 3 import static com.google.common.truth.Truth.assertThat; 4 import static org.robolectric.Shadows.shadowOf; 5 6 import android.app.IntentService; 7 import android.content.Intent; 8 import androidx.test.ext.junit.runners.AndroidJUnit4; 9 import org.junit.Test; 10 import org.junit.runner.RunWith; 11 12 @RunWith(AndroidJUnit4.class) 13 public class ShadowIntentServiceTest { 14 @Test shouldSetIntentRedelivery()15 public void shouldSetIntentRedelivery() { 16 IntentService intentService = new TestIntentService(); 17 ShadowIntentService shadowIntentService = shadowOf(intentService); 18 assertThat(shadowIntentService.getIntentRedelivery()).isFalse(); 19 intentService.setIntentRedelivery(true); 20 assertThat(shadowIntentService.getIntentRedelivery()).isTrue(); 21 intentService.setIntentRedelivery(false); 22 assertThat(shadowIntentService.getIntentRedelivery()).isFalse(); 23 } 24 25 private static class TestIntentService extends IntentService { TestIntentService()26 public TestIntentService() { 27 super("TestIntentService"); 28 } 29 30 @Override onHandleIntent(Intent intent)31 protected void onHandleIntent(Intent intent) { 32 } 33 } 34 } 35