aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-11-10 12:39:19 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-11-10 12:39:19 +0100
commitb67a0b2d866034dbf918f6fef3ef811701dc73fc (patch)
treec530a33d7f22c348a782e2c70b56d8728a1f21b5 /sonar-core
parentf2922e57b9ded98ab57fc56783bae11900a95bd9 (diff)
downloadsonarqube-b67a0b2d866034dbf918f6fef3ef811701dc73fc.tar.gz
sonarqube-b67a0b2d866034dbf918f6fef3ef811701dc73fc.zip
improve code coverage of DataCleaner classes
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java4
-rw-r--r--sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTaskTest.java28
-rw-r--r--sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/ProjectPurgeTaskTest.java11
3 files changed, 33 insertions, 10 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java
index aa08f1d2172..b405f04ae66 100644
--- a/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java
+++ b/sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java
@@ -20,6 +20,7 @@
package org.sonar.core.computation.dbcleaner;
+import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
@@ -60,7 +61,8 @@ public class DefaultPurgeTask implements PurgeTask {
return this;
}
- private boolean isNotViewNorSubview(String resourceQualifier) {
+ @VisibleForTesting
+ boolean isNotViewNorSubview(String resourceQualifier) {
return !(Qualifiers.VIEW.equals(resourceQualifier) || Qualifiers.SUBVIEW.equals(resourceQualifier));
}
diff --git a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTaskTest.java b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTaskTest.java
index a876cb251f5..17942e730c4 100644
--- a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTaskTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTaskTest.java
@@ -36,6 +36,7 @@ import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.argThat;
@@ -43,14 +44,24 @@ import static org.mockito.Mockito.*;
public class DefaultPurgeTaskTest {
+ private DefaultPurgeTask sut;
private ResourceDao resourceDao;
+ private PurgeDao purgeDao;
+ private Settings settings;
+ private DefaultPeriodCleaner periodCleaner;
+ private PurgeProfiler profiler;
@Before
public void before() throws Exception {
+ this.purgeDao = mock(PurgeDao.class);
this.resourceDao = mock(ResourceDao.class);
-
when(resourceDao.getResource(anyLong())).thenReturn(new ResourceDto().setQualifier(Qualifiers.PROJECT));
+ this.settings = mock(Settings.class);
+ this.periodCleaner = mock(DefaultPeriodCleaner.class);
+ this.profiler = mock(PurgeProfiler.class);
+
+ this.sut = new DefaultPurgeTask(purgeDao, resourceDao, settings, periodCleaner, profiler);
}
@Test
@@ -117,4 +128,19 @@ public class DefaultPurgeTaskTest {
verify(profiler).dump(anyLong(), any(Logger.class));
}
+ @Test
+ public void recognize_view_and_subview() {
+ boolean viewCheck = sut.isNotViewNorSubview(Qualifiers.VIEW);
+ boolean subViewCheck = sut.isNotViewNorSubview(Qualifiers.SUBVIEW);
+
+ assertThat(viewCheck).isFalse();
+ assertThat(subViewCheck).isFalse();
+ }
+
+ @Test
+ public void call_dao_delete_when_deleting() throws Exception {
+ sut.delete(123L);
+
+ verify(purgeDao, times(1)).deleteResourceTree(123L);
+ }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/ProjectPurgeTaskTest.java b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/ProjectPurgeTaskTest.java
index 1ba7d65497e..de25c313d07 100644
--- a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/ProjectPurgeTaskTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/ProjectPurgeTaskTest.java
@@ -33,12 +33,7 @@ import org.sonar.core.purge.PurgeProfiler;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class ProjectPurgeTaskTest {
@@ -78,7 +73,7 @@ public class ProjectPurgeTaskTest {
@Test
public void if_dao_purge_fails_it_should_not_interrupt_program_execution() throws Exception {
- when(dao.purge(any(PurgeConfiguration.class))).thenThrow(NullPointerException.class);
+ doThrow(RuntimeException.class).when(dao).purge(any(DbSession.class), any(PurgeConfiguration.class));
sut.purge(mock(DbSession.class), mock(PurgeConfiguration.class), mock(Settings.class));
@@ -87,7 +82,7 @@ public class ProjectPurgeTaskTest {
@Test
public void if_profiler_cleaning_fails_it_should_not_interrupt_program_execution() throws Exception {
- doThrow(NullPointerException.class).when(periodCleaner).clean(anyLong(), any(Settings.class));
+ doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class));
sut.purge(mock(DbSession.class), mock(PurgeConfiguration.class), mock(Settings.class));