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.junit.Assert.assertNotNull;
      5 import static org.robolectric.Shadows.shadowOf;
      6 
      7 import android.appwidget.AppWidgetHost;
      8 import android.appwidget.AppWidgetHostView;
      9 import android.appwidget.AppWidgetProviderInfo;
     10 import android.content.Context;
     11 import org.junit.Before;
     12 import org.junit.Test;
     13 import org.junit.runner.RunWith;
     14 import org.robolectric.RobolectricTestRunner;
     15 import org.robolectric.RuntimeEnvironment;
     16 
     17 @RunWith(RobolectricTestRunner.class)
     18 public class ShadowAppWidgetHostTest {
     19   private AppWidgetHost appWidgetHost;
     20   private ShadowAppWidgetHost shadowAppWidgetHost;
     21   private Context context;
     22 
     23   @Before
     24   public void setup() throws Exception {
     25     context = RuntimeEnvironment.application;
     26     appWidgetHost = new AppWidgetHost(context, 404);
     27     shadowAppWidgetHost = shadowOf(appWidgetHost);
     28   }
     29 
     30   @Test
     31   public void shouldKnowItsContext() throws Exception {
     32     assertThat(shadowAppWidgetHost.getContext()).isSameAs(context);
     33   }
     34 
     35   @Test
     36   public void shouldKnowItsHostId() throws Exception {
     37     assertThat(shadowAppWidgetHost.getHostId()).isEqualTo(404);
     38   }
     39 
     40   @Test
     41   public void createView_shouldReturnAppWidgetHostView() throws Exception {
     42     AppWidgetHostView hostView = appWidgetHost.createView(context, 0, null);
     43     assertNotNull(hostView);
     44   }
     45 
     46   @Test
     47   public void createView_shouldSetViewsContext() throws Exception {
     48     AppWidgetHostView hostView = appWidgetHost.createView(context, 0, null);
     49     assertThat(hostView.getContext()).isSameAs(context);
     50   }
     51 
     52   @Test
     53   public void createView_shouldSetViewsAppWidgetId() throws Exception {
     54     AppWidgetHostView hostView = appWidgetHost.createView(context, 765, null);
     55     assertThat(hostView.getAppWidgetId()).isEqualTo(765);
     56   }
     57 
     58   @Test
     59   public void createView_shouldSetViewsAppWidgetInfo() throws Exception {
     60     AppWidgetProviderInfo info = new AppWidgetProviderInfo();
     61     AppWidgetHostView hostView = appWidgetHost.createView(context, 0, info);
     62     assertThat(hostView.getAppWidgetInfo()).isSameAs(info);
     63   }
     64 
     65   @Test
     66   public void createView_shouldSetHostViewsHost() throws Exception {
     67     AppWidgetHostView hostView = appWidgetHost.createView(context, 0, null);
     68     assertThat(shadowOf(hostView).getHost()).isSameAs(appWidgetHost);
     69   }
     70 }
     71