• 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.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
6 
7 import android.content.Context;
8 import android.preference.EditTextPreference;
9 import android.widget.EditText;
10 import androidx.test.core.app.ApplicationProvider;
11 import androidx.test.ext.junit.runners.AndroidJUnit4;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 
16 @RunWith(AndroidJUnit4.class)
17 public class ShadowEditTextPreferenceTest {
18 
19   private static final String SOME_TEXT = "some text";
20   private EditTextPreference preference;
21 
22   private Context context;
23 
24   @Before
setup()25   public void setup() {
26     context = ApplicationProvider.getApplicationContext();
27     preference = new EditTextPreference(context);
28   }
29 
30   @Test
testConstructor()31   public void testConstructor() {
32     preference = new EditTextPreference(context);
33     assertNotNull(preference.getEditText());
34   }
35 
36   @Test
setTextInEditTextShouldStoreText()37   public void setTextInEditTextShouldStoreText() {
38     final EditText editText = preference.getEditText();
39     editText.setText(SOME_TEXT);
40 
41     assertThat(editText.getText().toString()).isEqualTo(SOME_TEXT);
42   }
43 
44   @Test
setTextShouldStoreText()45   public void setTextShouldStoreText() {
46     preference.setText("some other text");
47     assertThat(preference.getText()).isEqualTo("some other text");
48   }
49 
50   @Test
setTextShouldStoreNull()51   public void setTextShouldStoreNull() {
52     preference.setText(null);
53     assertNull(preference.getText());
54   }
55 }
56