@Test public void whenAPreferenceHasAnIncorrectType_returnsFalse_andShowsToastError() { putBooleanToSharedPrefs("password", false); PreferenceFragment fragment = Robolectric.buildFragment(TestPreferenceFragment.class).create().resume().visible().get(); AggregatePreferencesAdder loader = new AggregatePreferencesAdder(fragment); boolean result = loader.add(); assertFalse(result); String toastText = ShadowToast.getTextOfLatestToast(); assertEquals(toastText, getString(R.string.corrupt_imported_preferences_error)); }
public boolean add() { try { fragment.addPreferencesFromResource(R.xml.aggregate_preferences); return true; } catch (ClassCastException e) { Toast.makeText(fragment.getActivity(), R.string.corrupt_imported_preferences_error, Toast.LENGTH_LONG).show(); return false; } }
AggregatePreferencesAdder { public boolean add() { try { fragment.addPreferencesFromResource(R.xml.aggregate_preferences); return true; } catch (ClassCastException e) { Toast.makeText(fragment.getActivity(), R.string.corrupt_imported_preferences_error, Toast.LENGTH_LONG).show(); return false; } } }
AggregatePreferencesAdder { public boolean add() { try { fragment.addPreferencesFromResource(R.xml.aggregate_preferences); return true; } catch (ClassCastException e) { Toast.makeText(fragment.getActivity(), R.string.corrupt_imported_preferences_error, Toast.LENGTH_LONG).show(); return false; } } AggregatePreferencesAdder(PreferenceFragment fragment); }
AggregatePreferencesAdder { public boolean add() { try { fragment.addPreferencesFromResource(R.xml.aggregate_preferences); return true; } catch (ClassCastException e) { Toast.makeText(fragment.getActivity(), R.string.corrupt_imported_preferences_error, Toast.LENGTH_LONG).show(); return false; } } AggregatePreferencesAdder(PreferenceFragment fragment); boolean add(); }
AggregatePreferencesAdder { public boolean add() { try { fragment.addPreferencesFromResource(R.xml.aggregate_preferences); return true; } catch (ClassCastException e) { Toast.makeText(fragment.getActivity(), R.string.corrupt_imported_preferences_error, Toast.LENGTH_LONG).show(); return false; } } AggregatePreferencesAdder(PreferenceFragment fragment); boolean add();  }