@Test public void shouldFindByVersion() { when(finderByVersion.findByVersion(null, "1.2")) .thenReturn(new PastSnapshot("version", new Snapshot())); PastSnapshot variationSnapshot = finder.find(null, 2, "1.2"); verify(finderByVersion).findByVersion(null, "1.2"); assertThat(variationSnapshot.getIndex(), is(2)); assertThat(variationSnapshot.getMode(), is("version")); assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); }
private void initModulePastSnapshots() { periods = newLinkedList(); modulePastSnapshots = newLinkedList(); for (PastSnapshot projectPastSnapshot : periodsDefinition.getRootProjectPastSnapshots()) { Snapshot snapshot = findSnapshot(projectPastSnapshot.getProjectSnapshot()); PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot(); modulePastSnapshots.add(pastSnapshot); // When no snapshot is found, date of the period is null periods.add( new Period( pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAtMs()) : null)); LOG.info(pastSnapshot.toString()); } }
@Test public void shouldFindByPreviousAnalysis() throws ParseException { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); final Date date = format.parse("2010-05-18"); Snapshot snapshot = new Snapshot(); snapshot.setCreatedAt(date); when(finderByPreviousAnalysis.findByPreviousAnalysis(null)) .thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot)); PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); verify(finderByPreviousAnalysis).findByPreviousAnalysis(null); assertThat(variationSnapshot.getIndex(), is(2)); assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)); assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); }
@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())); }