@Test public void whenDeletingANotSavedStop_itShouldDoNothing() { when(settings.getString("saved_stops", "")).thenReturn("1_123,1_456,1_789"); subject.deleteSavedStop("1_589"); verify(editor, times(1)).putString("saved_stops", "1_123,1_456,1_789"); verify(editor, times(1)).apply(); }
@Test public void whenDeletingLastSavedStop_itShouldCommitEmptyString() { when(settings.getString("saved_stops", "")).thenReturn("1_456"); subject.deleteSavedStop("1_456"); verify(editor).putString("saved_stops", ""); verify(editor).apply(); }
@Test public void whenDeletingAnExistingStop_itShouldDeleteFromSettings() { when(settings.getString("saved_stops", "")).thenReturn("1_123,1_456,1_789"); subject.deleteSavedStop("1_456"); verify(editor).putString("saved_stops", "1_123,1_789"); verify(editor).apply(); }
@Test public void onAddingSavedStops_shouldSaveAllStops() { when(settings.getString("saved_stops", "")).thenReturn("1_123,1_456,1_789"); subject.addSavedStop("1_589"); verify(editor, times(1)).putString("saved_stops", "1_123,1_456,1_789,1_589"); verify(editor, times(1)).apply(); }
@Test public void onSomeSavedStops_shouldHaveSavedStops() { when(settings.getString("saved_stops", "")).thenReturn("1_123,1_456,1_789"); assertThat(subject.getSavedStops()) .isEqualTo( new ArrayList<String>() { { add("1_123"); add("1_456"); add("1_789"); } }); }
@Test public void onNoSavedStops_shouldHaveEmptyList() { when(settings.getString("saved_stops", "")).thenReturn(""); assertThat(subject.getSavedStops().size()).isEqualTo(0); }