182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppypackage com.xtremelabs.robolectric.shadows; 282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport static org.junit.Assert.assertEquals; 482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport static org.junit.Assert.assertSame; 582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport static org.mockito.Mockito.mock; 682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport com.xtremelabs.robolectric.Robolectric; 882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport com.xtremelabs.robolectric.WithTestDefaultsRunner; 982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 1082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport org.junit.Test; 1182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport org.junit.runner.RunWith; 1282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 139e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppyimport android.content.Context; 1482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.AdapterView.OnItemClickListener; 1582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.ArrayAdapter; 1682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppyimport android.widget.AutoCompleteTextView; 1782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 1882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy@RunWith(WithTestDefaultsRunner.class) 1982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppypublic class ShadowAutoCompleteTextViewTest { 2082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 2182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy @Test 2282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy public void shouldStoreAdapter() { 2382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy AutoCompleteTextView autoCompleteTextView = 2482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy new AutoCompleteTextView(Robolectric.application); 2582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(Robolectric.application, 0); 2682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 2782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy autoCompleteTextView.setAdapter(adapter); 2882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 2982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy assertSame(adapter, autoCompleteTextView.getAdapter()); 3082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy } 3182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 3282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy @Test 3382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy public void shouldHaveDefaultThresholdOfTwo() { 3482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy AutoCompleteTextView autoCompleteTextView = 3582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy new AutoCompleteTextView(Robolectric.application); 3682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 3782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy assertEquals(2, autoCompleteTextView.getThreshold()); 3882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy } 3982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 4082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy @Test 4182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy public void shouldStoreThreshold() { 4282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy AutoCompleteTextView autoCompleteTextView = 4382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy new AutoCompleteTextView(Robolectric.application); 4482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 4582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy autoCompleteTextView.setThreshold(123); 4682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 4782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy assertEquals(123, autoCompleteTextView.getThreshold()); 4882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy } 4982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 5082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy @Test 5182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy public void shouldNotStoreThresholdLessThanOne() { 5282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy AutoCompleteTextView autoCompleteTextView = 5382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy new AutoCompleteTextView(Robolectric.application); 5482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 5582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy autoCompleteTextView.setThreshold(-1); 5682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 5782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy assertEquals(1, autoCompleteTextView.getThreshold()); 5882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy } 5982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 6082ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy @Test 6182ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy public void shouldStoreOnItemClickListener() { 6282ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy AutoCompleteTextView autoCompleteTextView = 6382ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy new AutoCompleteTextView(Robolectric.application); 6482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy OnItemClickListener listener = mock(OnItemClickListener.class); 6582ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 6682ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy autoCompleteTextView.setOnItemClickListener(listener); 6782ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy 6882ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy assertSame(listener, autoCompleteTextView.getOnItemClickListener()); 6982ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy } 709e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 719e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy @Test 729e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy public void shouldReplaceTextAndUpdateSelection() { 739e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy String text = "hello world"; 749e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy ReplaceableAutoCompleteTextView autoCompleteTextView = 759e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy new ReplaceableAutoCompleteTextView(Robolectric.application); 769e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 779e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy autoCompleteTextView.publicReplaceText(text); 789e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 799e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy assertEquals(text, autoCompleteTextView.getText().toString()); 809e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy assertEquals(text.length(), autoCompleteTextView.getSelectionStart()); 819e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy assertEquals(text.length(), autoCompleteTextView.getSelectionEnd()); 829e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy } 839e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 849e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy private static class ReplaceableAutoCompleteTextView extends AutoCompleteTextView { 859e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 869e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy public ReplaceableAutoCompleteTextView(Context context) { 879e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy super(context); 889e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy } 899e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy 909e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy public void publicReplaceText(CharSequence text) { 919e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy replaceText(text); 929e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy } 939e9e1162d3d3a1714c0f9d196afcda6851f74112John Stuppy } 9482ab6d9429def7ae3bb62eec2da768eb45483a50John Stuppy} 95