aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-09-26 11:43:32 +0200
committersonartech <sonartech@sonarsource.com>2018-10-03 09:28:21 +0200
commit421b38b41c7ac19c44f1b264e6262740db0d9e4d (patch)
tree757868fd1d5ba147f60c20216ca0a9dcb3047db0 /server/sonar-ce-task-projectanalysis
parentade9096666b24dac7a60ec294393bdc9421fe49d (diff)
downloadsonarqube-421b38b41c7ac19c44f1b264e6262740db0d9e4d.tar.gz
sonarqube-421b38b41c7ac19c44f1b264e6262740db0d9e4d.zip
polish design of PeriodHolder
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolder.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolderImpl.java1
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java16
3 files changed, 11 insertions, 12 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolder.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolder.java
index ba7d733c79a..8c6f6c7597b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolder.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolder.java
@@ -19,8 +19,6 @@
*/
package org.sonar.ce.task.projectanalysis.period;
-import javax.annotation.CheckForNull;
-
/**
* Repository of period used to compute differential measures.
* Here are the steps to retrieve the period :
@@ -40,9 +38,9 @@ public interface PeriodHolder {
/**
* Retrieve the period from the Holder.
*
- * @throws IllegalStateException if the periods haven't been initialized
+ * @throws IllegalStateException if the period hasn't been initialized
+ * @throws IllegalStateException if there is no period
*/
- @CheckForNull
Period getPeriod();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolderImpl.java
index f2de306664e..69847a98fb0 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolderImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/PeriodHolderImpl.java
@@ -50,6 +50,7 @@ public class PeriodHolderImpl implements PeriodHolder {
@Override
public Period getPeriod() {
checkHolderIsInitialized();
+ checkState(period != null, "There is no period. Use hasPeriod() before calling this method");
return period;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java
index 92f8768d7c5..70284f87c7f 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java
@@ -96,7 +96,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
// No project, no snapshot
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -128,7 +128,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "UNKNWOWN VERSION");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -141,7 +141,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -154,7 +154,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "100");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -219,7 +219,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "2008-11-30");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -257,7 +257,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "0");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -322,7 +322,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "previous_version");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
@Test
@@ -401,7 +401,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
settings.setProperty("sonar.leak.period", "0.8");
underTest.execute(new TestComputationStepContext());
- assertThat(periodsHolder.getPeriod()).isNull();
+ assertThat(periodsHolder.hasPeriod()).isFalse();
}
private void setupRoot(ComponentDto project) {