### Question:
PreferencesBasedRepository implements Repository { @Override public void add(MiniHabit miniHabit) { Set<MiniHabit> list = findAll(); list.add(miniHabit); prefs.putString("mini_habits", asString(list)); prefs.flush(); } 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 add() { context.checking(new Expectations() {{ oneOf(preferences).getString("mini_habits"); will(returnValue("One Pushup:1")); oneOf(preferences).putString("mini_habits", "One Pushup:1,Cooking:3"); oneOf(preferences).flush(); }}); repo.add(new MiniHabit("Cooking", 3));; }