public List<RuleFailureModel> getPastViolations(Resource resource) {
Snapshot snapshot = resourcePersister.getSnapshot(resource);
+ if (snapshot == null) { // TODO Godin: Prevent NPE with Natural and VB plugins
+ return Collections.emptyList();
+ }
Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, true);
if (previousLastSnapshot == null) {
return Collections.emptyList();
import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Resource;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@Test
public void shouldGetPastResourceViolations() {
Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
+ doReturn(snapshot).when(resourcePersister)
+ .getSnapshot(any(Resource.class));
doReturn(snapshot).when(resourcePersister)
.getLastSnapshot(any(Snapshot.class), anyBoolean());