]> source.dussan.org Git - sonarqube.git/blob
341b5107c4c02a421e39bcab7191fbd3d39d2a96
[sonarqube.git] /
1 package org.sonar.plugins.core.timemachine;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.sonar.api.database.model.RuleFailureModel;
6 import org.sonar.api.database.model.Snapshot;
7 import org.sonar.api.resources.JavaFile;
8 import org.sonar.api.resources.Resource;
9 import org.sonar.batch.index.ResourcePersister;
10 import org.sonar.jpa.test.AbstractDbUnitTestCase;
11
12 import java.util.List;
13
14 import static org.hamcrest.CoreMatchers.is;
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.Matchers.notNullValue;
17 import static org.mockito.Matchers.any;
18 import static org.mockito.Matchers.anyBoolean;
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.mock;
21
22 public class PastViolationsLoaderTest extends AbstractDbUnitTestCase {
23
24   private ResourcePersister resourcePersister;
25   private PastViolationsLoader loader;
26
27   @Before
28   public void setUp() {
29     setupData("shared");
30     resourcePersister = mock(ResourcePersister.class);
31     loader = new PastViolationsLoader(getSession(), resourcePersister);
32   }
33
34   @Test
35   public void shouldGetPastResourceViolations() {
36     Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
37     doReturn(snapshot).when(resourcePersister)
38         .getSnapshot(any(Resource.class));
39     doReturn(snapshot).when(resourcePersister)
40         .getLastSnapshot(any(Snapshot.class), anyBoolean());
41
42     List<RuleFailureModel> violations = loader.getPastViolations(new JavaFile("file"));
43
44     assertThat(violations.size(), is(2));
45   }
46
47   @Test
48   public void shouldReturnEmptyList() {
49     List<RuleFailureModel> violations = loader.getPastViolations(null);
50
51     assertThat(violations, notNullValue());
52     assertThat(violations.size(), is(0));
53   }
54
55 }