behavior. AudioManager audioManager = Mockito.mock(AudioManager.class); Mockito.when(audioManager.getRingerMode()) .thenReturn(RINGER_MODE_SILENT); ! // Test the code of interest. maximizeVolume(audioManager); ! // Validate that we saw exactly what we wanted. Mockito.verify(audioManager).getRingerMode(); Mockito.verifyNoMoreInteractions(audioManager); }
behavior. AudioManager audioManager = mock(AudioManager.class); when(audioManager.getRingerMode()) .thenReturn(RINGER_MODE_NORMAL); when(audioManager.getStreamMaxVolume(STREAM_RING)) .thenReturn(100); ! // Test the code of interest. maximizeVolume(audioManager); ! // Validate that we saw exactly what we wanted. verify(audioManager) .setStreamVolume(STREAM_RING, 100, 0); }
does not show any errors. assertThat(username).hasNoError(); assertThat(password).hasNoError(); instrumentation.runOnMainSync(new Runnable() { @Override public void run() { // Type a value into the username and password fields. username.setText("prateek"); password.setText(“password”); // Click the "login" button. login.performClick(); } }); instrumentation.waitForIdleSync(); ! // Verify error was shown only for username field. assertThat(username).hasNoError(); assertThat(password).hasError(R.string.password_length); }
does not show any errors. assertThat(username).hasNoError(); assertThat(password).hasNoError(); ! // Type a value into the username and password fields. solo.typeText(username, “prateek”); solo.typeText(password, “password”); // Click the "login" button. solo.clickOnView(login); ! // Verify error was shown only for username field. assertThat(username).hasNoError(); assertThat(password).hasError(R.string.password_length); }
does not show any errors. assertThat(username).hasNoError(); assertThat(password).hasNoError(); ! // Type a value into the username and password fields. onView(withId(R.id.username)).perform(typeText("prateek")); onView(withId(R.id.password)).perform(typeText("password")); onView(withId(R.id.login)).perform(click()); ! // Verify error was shown only for username field. assertThat(username).hasNoError(); assertThat(password).hasError(R.string.password_length); }