### Question:
PreferencesBasedRepository implements Repository { @Override public Set<MiniHabit> findAll() { String text = prefs.getString("mini_habits"); if (text == null || text.trim().isEmpty()) return new LinkedHashSet<MiniHabit>(); return newMiniHabits(text); } PreferencesBasedRepository(Preferences prefs); @Override Set<MiniHabit> findAll(); @Override void add(MiniHabit miniHabit); @Override void update(Collection<MiniHabit> list); @Override void updateProgressDate(DateAtMidnight aDate); @Override DateAtMidnight lastFeedbackDate();  }### Answer:
@Test public void no_habits() { context.checking(new Expectations() {{ oneOf(preferences).getString("mini_habits"); will(returnValue("")); }}); assertTrue(repo.findAll().isEmpty()); }
@Test public void two_habits() { context.checking(new Expectations() {{ oneOf(preferences).getString("mini_habits"); will(returnValue("One Pushup:1, Cooking:2")); }}); assertEquals(2, repo.findAll().size()); }
@Test public void one_minihabit_with_days_in_progress() { context.checking(new Expectations() {{ oneOf(preferences).getString("mini_habits"); will(returnValue("One Pushup:3")); }}); MiniHabit habit = repo.findAll().iterator().next(); assertEquals("One Pushup", habit.label()); assertEquals(3, habit.daysInProgress()); }