@Before public void setUp() { rightNow = new Date(); tenDaysAgo = DateUtils.addDays(rightNow, -10); fiveDaysAgo = DateUtils.addDays(rightNow, -5); PastSnapshot pastSnapshot = mock(PastSnapshot.class); when(pastSnapshot.getIndex()).thenReturn(1); when(pastSnapshot.getTargetDate()).thenReturn(fiveDaysAgo); PastSnapshot pastSnapshot2 = mock(PastSnapshot.class); when(pastSnapshot2.getIndex()).thenReturn(2); when(pastSnapshot2.getTargetDate()).thenReturn(tenDaysAgo); timeMachineConfiguration = mock(TimeMachineConfiguration.class); when(timeMachineConfiguration.getProjectPastSnapshots()) .thenReturn(Arrays.asList(pastSnapshot, pastSnapshot2)); context = mock(DecoratorContext.class); resource = new File("com/foo/bar"); when(context.getResource()).thenReturn(resource); notificationManager = mock(NotificationManager.class); decorator = new NewViolationsDecorator(timeMachineConfiguration, notificationManager); rule1 = Rule.create().setRepositoryKey("rule1").setKey("rule1").setName("name1"); rule2 = Rule.create().setRepositoryKey("rule2").setKey("rule2").setName("name2"); rule3 = Rule.create().setRepositoryKey("rule3").setKey("rule3").setName("name3"); }
void persistConfiguration() { List<PastSnapshot> pastSnapshots = configuration.getProjectPastSnapshots(); for (PastSnapshot pastSnapshot : pastSnapshots) { projectSnapshot = session.reattach(Snapshot.class, projectSnapshot.getId()); projectSnapshot.setPeriodMode(pastSnapshot.getIndex(), pastSnapshot.getMode()); projectSnapshot.setPeriodModeParameter( pastSnapshot.getIndex(), pastSnapshot.getModeParameter()); projectSnapshot.setPeriodDate(pastSnapshot.getIndex(), pastSnapshot.getTargetDate()); session.save(projectSnapshot); } session.commit(); }