2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.core.timemachine;
22 import org.apache.commons.configuration.PropertiesConfiguration;
23 import org.junit.Test;
24 import org.sonar.api.CoreProperties;
25 import org.sonar.api.database.model.Snapshot;
26 import org.sonar.jpa.test.AbstractDbUnitTestCase;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.mockito.Mockito.*;
36 public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
39 public void shouldSkipTendencies() {
40 PropertiesConfiguration conf = new PropertiesConfiguration();
41 conf.setProperty(CoreProperties.SKIP_TENDENCIES_PROPERTY, true);
42 assertThat(new TimeMachineConfiguration(conf).skipTendencies(), is(true));
46 public void shouldNotSkipTendenciesByDefault() {
47 PropertiesConfiguration conf = new PropertiesConfiguration();
48 assertThat(new TimeMachineConfiguration(conf).skipTendencies(), is(false));
52 public void shouldInitVariationSnapshots() throws ParseException {
53 PropertiesConfiguration conf = new PropertiesConfiguration();
54 PastSnapshotFinder snapshotReferenceFinder = mock(PastSnapshotFinder.class);
55 when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15")));
56 when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13")));
58 TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, snapshotReferenceFinder);
60 verify(snapshotReferenceFinder).find(conf, 1);
61 verify(snapshotReferenceFinder).find(conf, 2);
62 verify(snapshotReferenceFinder).find(conf, 3);
64 assertThat(timeMachineConfiguration.getProjectPastSnapshots().size(), is(2));
67 private Snapshot newSnapshot(String date) throws ParseException {
68 Date createdAt = new SimpleDateFormat("yyyy-MM-dd").parse(date);
69 return new Snapshot().setCreatedAt(createdAt);