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.app.ProgressDialog;
      7 import android.view.View;
      8 import org.junit.Before;
      9 import org.junit.Test;
     10 import org.junit.runner.RunWith;
     11 import org.robolectric.RobolectricTestRunner;
     12 import org.robolectric.RuntimeEnvironment;
     13 import org.robolectric.Shadows;
     14 
     15 @RunWith(RobolectricTestRunner.class)
     16 public class ShadowProgressDialogTest {
     17 
     18   private ProgressDialog dialog;
     19   private ShadowProgressDialog shadow;
     20 
     21   @Before
     22   public void setUp() {
     23     dialog = new ProgressDialog(RuntimeEnvironment.application);
     24     shadow = Shadows.shadowOf(dialog);
     25   }
     26 
     27   @Test
     28   public void shouldExtendAlertDialog() {
     29     assertThat(shadow).isInstanceOf(ShadowAlertDialog.class);
     30   }
     31 
     32   @Test
     33   public void shouldPutTheMessageIntoTheView() {
     34     String message = "This is only a test";
     35     shadow.callOnCreate(null);
     36 
     37     View dialogView = shadow.getView();
     38     assertThat(shadowOf(dialogView).innerText()).doesNotContain(message);
     39     dialog.setMessage(message);
     40     assertThat(shadowOf(shadow.getView()).innerText()).contains(message);
     41   }
     42 
     43   @Test
     44   public void shouldSetIndeterminate() {
     45     assertThat(dialog.isIndeterminate()).isFalse();
     46 
     47     dialog.setIndeterminate(true);
     48     assertThat(dialog.isIndeterminate()).isTrue();
     49 
     50     dialog.setIndeterminate(false);
     51     assertThat(dialog.isIndeterminate()).isFalse();
     52   }
     53 
     54   @Test
     55   public void shouldSetMax() {
     56     assertThat(dialog.getMax()).isEqualTo(0);
     57 
     58     dialog.setMax(41);
     59     assertThat(dialog.getMax()).isEqualTo(41);
     60   }
     61 
     62   @Test
     63   public void shouldSetProgress() {
     64     assertThat(dialog.getProgress()).isEqualTo(0);
     65 
     66     dialog.setProgress(42);
     67     assertThat(dialog.getProgress()).isEqualTo(42);
     68   }
     69 
     70   @Test
     71   public void shouldGetProgressStyle() {
     72     assertThat(shadow.getProgressStyle()).isEqualTo(ProgressDialog.STYLE_SPINNER);
     73 
     74     dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
     75     assertThat(shadow.getProgressStyle()).isEqualTo(ProgressDialog.STYLE_HORIZONTAL);
     76 
     77     dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     78     assertThat(shadow.getProgressStyle()).isEqualTo(ProgressDialog.STYLE_SPINNER);
     79   }
     80 
     81   @Test
     82   public void horizontalStyle_shouldGetMessage() {
     83     String message = "This is only a test";
     84     shadow.callOnCreate(null);
     85 
     86     dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
     87     dialog.setMessage(message);
     88 
     89     assertThat(shadow.getMessage()).contains(message);
     90   }
     91 
     92   @Test
     93   public void spinnerStyle_shouldGetMessage() {
     94     String message = "This is only a test";
     95     shadow.callOnCreate(null);
     96 
     97     dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
     98     dialog.setMessage(message);
     99 
    100     assertThat(shadow.getMessage()).contains(message);
    101   }
    102 }
    103