@Test public void testPhotoListManagerDidFinish_withNoPhotos_ShowsToast() { List emptyFlickrPhotoList = new ArrayList<FlickrPhoto>(); subject.photoListManagerDidFinish(emptyFlickrPhotoList); Toast actualToast = ShadowToast.getLatestToast(); Assertions.assertThat(actualToast).isNotNull(); String actualToastText = ShadowToast.getTextOfLatestToast(); Assertions.assertThat(actualToastText).isEqualTo("Flickr api response malformed"); }
@Test public void testRefreshBluetooth() { ShadowActivity shadowActivity = Shadows.shadowOf(activity); activity.findViewById(R.id.refresh_bluetooth).performClick(); assertEquals( "Unexpected toast text", shadowActivity.getString(R.string.scan_for_devices), ShadowToast.getTextOfLatestToast()); }
@Test public void testBluetoothSelected_nochange() { ShadowActivity shadowActivity = Shadows.shadowOf(activity); activity.selectedItemTV.setText("No Device Selected!"); activity.findViewById(R.id.done_selecting).performClick(); assertEquals( "Unexpected toast text", shadowActivity.getString(R.string.no_change_to_device), ShadowToast.getTextOfLatestToast()); assertTrue("finish() was not called", shadowActivity.isFinishing()); }
// Should pass @Test public void testButtonOneClick_shouldShowToast() { MainActivity activity = Robolectric.setupActivity(MainActivity.class); activity.findViewById(R.id.button_1).performClick(); ShadowLooper.idleMainLooper(); // Check toast correctness Assert.assertTrue(ShadowToast.getTextOfLatestToast().equals("Button #1 Clicked")); // Check textView text TextView textView = (TextView) activity.findViewById(R.id.test_text); Assert.assertTrue("Button 1 Clicked".equals(textView.getText())); }