@Test public void shouldNotFindByDate() throws ParseException { when(finderByDate.findByDate((Snapshot) anyObject(), (Date) anyObject())).thenReturn(null); PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); verify(finderByDate).findByDate((Snapshot) anyObject(), (Date) anyObject()); assertNull(variationSnapshot); }
@Test public void shouldFindByDate() throws ParseException { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); final Date date = format.parse("2010-05-18"); when(finderByDate.findByDate(null, date)).thenReturn(new PastSnapshot("date", new Snapshot())); PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); verify(finderByDate) .findByDate( (Snapshot) anyObject(), argThat( new BaseMatcher<Date>() { public boolean matches(Object o) { return o.equals(date); } public void describeTo(Description description) {} })); assertThat(variationSnapshot.getIndex(), is(2)); assertThat(variationSnapshot.getMode(), is("date")); assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); }