Home | History | Annotate | Download | only in robolectric
      1 package org.robolectric;
      2 
      3 import static com.google.common.truth.Truth.assertThat;
      4 
      5 import android.database.CursorWrapper;
      6 import java.util.Arrays;
      7 import java.util.Collection;
      8 import org.junit.Test;
      9 import org.junit.runner.RunWith;
     10 import org.robolectric.annotation.Config;
     11 import org.robolectric.annotation.Implementation;
     12 import org.robolectric.annotation.Implements;
     13 import org.robolectric.shadows.ShadowCursorWrapper;
     14 
     15 /**
     16  * Parameterized tests using custom shadow classes.
     17  *
     18  * @author John Ferlisi
     19  */
     20 @RunWith(ParameterizedRobolectricTestRunner.class)
     21 public final class ParameterizedRobolectricTestRunnerConfigTest {
     22 
     23   private final int expectedType;
     24 
     25   public ParameterizedRobolectricTestRunnerConfigTest(int expectedType) {
     26     this.expectedType = expectedType;
     27   }
     28 
     29   @Test
     30   @Config(manifest = Config.NONE, shadows = ShadowCursorWrapper1.class)
     31   public void getType1() {
     32     assertThat(new CursorWrapper(null).getType(expectedType)).isEqualTo(1);
     33   }
     34 
     35   @Test
     36   @Config(manifest = Config.NONE, shadows = ShadowCursorWrapperEcho.class)
     37   public void getTypeEcho() {
     38     assertThat(new CursorWrapper(null).getType(expectedType)).isEqualTo(expectedType);
     39   }
     40 
     41   @ParameterizedRobolectricTestRunner.Parameters(name = "ConfigTest: {0}")
     42   public static Collection getTestData() {
     43     Object[][] data = {
     44         { 1 },
     45         { 2 },
     46         { 3 },
     47         { 4 }
     48     };
     49     return Arrays.asList(data);
     50   }
     51 
     52   @Implements(CursorWrapper.class)
     53   public static class ShadowCursorWrapper1 extends ShadowCursorWrapper {
     54 
     55     @Implementation
     56     @Override
     57     public int getType(int columnIndex) {
     58       return 1;
     59     }
     60   }
     61 
     62   @Implements(CursorWrapper.class)
     63   public static class ShadowCursorWrapperEcho extends ShadowCursorWrapper {
     64 
     65     @Implementation
     66     @Override
     67     public int getType(int columnIndex) {
     68       return columnIndex;
     69     }
     70   }
     71 }
     72