Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static org.assertj.core.api.Assertions.assertThat;
      4 import static org.robolectric.Shadows.shadowOf;
      5 
      6 import android.appwidget.AppWidgetHost;
      7 import android.appwidget.AppWidgetHostView;
      8 import android.appwidget.AppWidgetProviderInfo;
      9 import org.junit.Before;
     10 import org.junit.Test;
     11 import org.junit.runner.RunWith;
     12 import org.robolectric.RobolectricTestRunner;
     13 import org.robolectric.RuntimeEnvironment;
     14 
     15 @RunWith(RobolectricTestRunner.class)
     16 public class ShadowAppWidgetHostViewTest {
     17   private AppWidgetHostView appWidgetHostView;
     18   private ShadowAppWidgetHostView shadowAppWidgetHostView;
     19 
     20   @Before
     21   public void setUp() throws Exception {
     22     appWidgetHostView = new AppWidgetHostView(RuntimeEnvironment.application);
     23     shadowAppWidgetHostView = shadowOf(appWidgetHostView);
     24   }
     25 
     26   @Test
     27   public void shouldKnowItsWidgetId() throws Exception {
     28     appWidgetHostView.setAppWidget(789, null);
     29     assertThat(appWidgetHostView.getAppWidgetId()).isEqualTo(789);
     30   }
     31 
     32   @Test
     33   public void shouldKnowItsAppWidgetProviderInfo() throws Exception {
     34     AppWidgetProviderInfo providerInfo = new AppWidgetProviderInfo();
     35     appWidgetHostView.setAppWidget(0, providerInfo);
     36     assertThat(appWidgetHostView.getAppWidgetInfo()).isSameAs(providerInfo);
     37   }
     38 
     39   @Test
     40   public void shouldHaveNullHost() throws Exception {
     41     assertThat(shadowAppWidgetHostView.getHost()).isNull();
     42   }
     43 
     44   @Test
     45   public void shouldBeAbleToHaveHostSet() throws Exception {
     46     AppWidgetHost host = new AppWidgetHost(RuntimeEnvironment.application, 0);
     47     shadowAppWidgetHostView.setHost(host);
     48     assertThat(shadowAppWidgetHostView.getHost()).isSameAs(host);
     49   }
     50 }
     51