@Test public void findAllReturnsEmptyListIfNoTrophies() { reset(trophyDAO); when(trophyDAO.retrieveAll()).thenReturn(Collections.<Trophy>emptyList()); underTest.refreshTrophies(); assertEquals(Collections.EMPTY_LIST, underTest.findAll()); }
@Test public void findsAndReturnsAllTrophiesForAGivenGameType() { final Collection<Trophy> trophies = underTest.findForGameType(GAME_TYPE); assertThat(trophies.size(), is(equalTo(2))); assertThat(trophies, hasItem(TROPHY1)); assertThat(trophies, hasItem(TROPHY2)); }
@Before public void setUp() { trophyDAO = mock(TrophyDAO.class); when(trophyDAO.retrieveAll()).thenReturn(asList(TROPHY1, TROPHY2, TROPHY3)); underTest = new CachingTrophyRepository(trophyDAO); underTest.refreshTrophies(); }
@Test public void saveShouldWriteTheTrophyToTheDAO() { final Trophy trophy = new Trophy(); trophy.setId(new BigDecimal(666)); underTest.save(trophy); verify(trophyDAO).save(trophy); }
@Test public void findByNameReturnsEmptyCollectionWhenNoEntries() throws Exception { final Collection<Trophy> results = underTest.findByName("Foo"); assertTrue(results.isEmpty()); }
@Test public void findAllReadsTheInitialisedTrophies() { assertThat(underTest.findAll(), allOf(hasItem(TROPHY1), hasItem(TROPHY2), hasItem(TROPHY3))); }
@Test public void findByIdReturnsNullIfNoMatchFound() { final Trophy trophy = underTest.findById(INVALID_TROPHY_ID); assertThat(trophy, is(nullValue())); }
@Test public void findByIdReturnsMatchingTrophy() { final Trophy trophy = underTest.findById(TROPHY1.getId()); assertThat(trophy, is(equalTo(TROPHY1))); }
@Test public void findsAndReturnsEmptyCollectionIfNoTrophiesArePossessedByAGivenGameType() { final Collection<Trophy> trophies = underTest.findForGameType(GAME_TYPE_WITHOUT_TROPHIES); assertThat(trophies.size(), is(equalTo(0))); }
@Test public void findByNameReturnsCollectionOfTrophiesMatchingName() throws Exception { Collection<Trophy> results = underTest.findByName("trophyTwo"); assertEquals(1, results.size()); assertEquals(TROPHY2, results.iterator().next()); }