1package com.xtremelabs.robolectric.shadows; 2 3import org.junit.Before; 4import org.junit.Test; 5import org.junit.runner.RunWith; 6 7import android.app.Activity; 8import android.view.inputmethod.InputMethodManager; 9 10import com.xtremelabs.robolectric.Robolectric; 11import com.xtremelabs.robolectric.WithTestDefaultsRunner; 12 13import static org.hamcrest.CoreMatchers.equalTo; 14import static org.junit.Assert.assertThat; 15 16@RunWith(WithTestDefaultsRunner.class) 17public class InputMethodManagerTest { 18 19 private InputMethodManager manager; 20 private ShadowInputMethodManager shadow; 21 22 @Before 23 public void setUp() throws Exception { 24 manager = (InputMethodManager) Robolectric.application.getSystemService(Activity.INPUT_METHOD_SERVICE); 25 shadow = Robolectric.shadowOf(manager); 26 } 27 28 @Test 29 public void shouldRecordSoftInputVisibility() { 30 assertThat(shadow.isSoftInputVisible(), equalTo(false)); 31 32 manager.showSoftInput(null, 0); 33 assertThat(shadow.isSoftInputVisible(), equalTo(true)); 34 35 manager.hideSoftInputFromWindow(null, 0); 36 assertThat(shadow.isSoftInputVisible(), equalTo(false)); 37 } 38} 39