• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ProgressDialog;
7 import android.view.View;
8 import androidx.test.core.app.ApplicationProvider;
9 import androidx.test.ext.junit.runners.AndroidJUnit4;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.robolectric.Shadows;
14 
15 @RunWith(AndroidJUnit4.class)
16 public class ShadowProgressDialogTest {
17 
18   private ProgressDialog dialog;
19   private ShadowProgressDialog shadow;
20 
21   @Before
setUp()22   public void setUp() {
23     dialog = new ProgressDialog(ApplicationProvider.getApplicationContext());
24     shadow = Shadows.shadowOf(dialog);
25   }
26 
27   @Test
shouldExtendAlertDialog()28   public void shouldExtendAlertDialog() {
29     assertThat(shadow).isInstanceOf(ShadowAlertDialog.class);
30   }
31 
32   @Test
shouldPutTheMessageIntoTheView()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
shouldSetIndeterminate()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
shouldSetMax()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
shouldSetProgress()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
shouldGetProgressStyle()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
horizontalStyle_shouldGetMessage()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().toString()).contains(message);
90   }
91 
92   @Test
spinnerStyle_shouldGetMessage()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().toString()).contains(message);
101   }
102 }
103