1 package org.sonar.plugins.core.timemachine;
3 import org.junit.Before;
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;
12 import java.util.List;
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;
22 public class PastViolationsLoaderTest extends AbstractDbUnitTestCase {
24 private ResourcePersister resourcePersister;
25 private PastViolationsLoader loader;
30 resourcePersister = mock(ResourcePersister.class);
31 loader = new PastViolationsLoader(getSession(), resourcePersister);
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());
42 List<RuleFailureModel> violations = loader.getPastViolations(new JavaFile("file"));
44 assertThat(violations.size(), is(2));
48 public void shouldReturnEmptyList() {
49 List<RuleFailureModel> violations = loader.getPastViolations(null);
51 assertThat(violations, notNullValue());
52 assertThat(violations.size(), is(0));