aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-10-21 09:51:09 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-10-21 16:47:41 +0200
commitdd15f598e92b44189952cd6a1f5ad02f937c862d (patch)
tree0df76737a5eb7d327c0458841938063ff08fe77a /sonar-plugin-api
parentd608bb523728924bc6f8f60b2d41517838f2a7f4 (diff)
downloadsonarqube-dd15f598e92b44189952cd6a1f5ad02f937c862d.tar.gz
sonarqube-dd15f598e92b44189952cd6a1f5ad02f937c862d.zip
SONAR-8192 improve coverage of AlwaysIncreasingSystem2
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2Test.java52
2 files changed, 52 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2.java
index 51150f14707..e2971cf0125 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.utils.internal;
-import com.google.common.base.Preconditions;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
@@ -41,7 +40,7 @@ public class AlwaysIncreasingSystem2 extends System2 {
private AlwaysIncreasingSystem2(Supplier<Long> initialValueSupplier, long increment) {
checkArgument(increment > 0, "increment must be > 0");
long initialValue = initialValueSupplier.get();
- Preconditions.checkArgument(initialValue >= 0, "Initial value must be >= 0");
+ checkArgument(initialValue >= 0, "Initial value must be >= 0");
this.now = new AtomicLong(initialValue);
this.increment = increment;
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2Test.java
index bb14c47feaa..bc78432979c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2Test.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/AlwaysIncreasingSystem2Test.java
@@ -20,12 +20,15 @@
package org.sonar.api.utils.internal;
import javax.annotation.Nullable;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
public class AlwaysIncreasingSystem2Test {
-
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
@Test
public void default_constructor_makes_now_start_with_random_number_and_increase_returned_value_by_100_with_each_call() {
@@ -47,6 +50,53 @@ public class AlwaysIncreasingSystem2Test {
verifyValuesReturnedByNow(underTest, 777777L, 96);
}
+ @Test
+ public void constructor_with_initial_value_and_increment_throws_IAE_if_initial_value_is_less_than_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Initial value must be >= 0");
+
+ new AlwaysIncreasingSystem2(-1, 100);
+ }
+
+ @Test
+ public void constructor_with_initial_value_and_increment_accepts_initial_value_0() {
+ AlwaysIncreasingSystem2 underTest = new AlwaysIncreasingSystem2(0, 100);
+
+ verifyValuesReturnedByNow(underTest, 0L, 100);
+ }
+
+ @Test
+ public void constructor_with_initial_value_and_increment_throws_IAE_if_increment_is_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("increment must be > 0");
+
+ new AlwaysIncreasingSystem2(10, 0);
+ }
+
+ @Test
+ public void constructor_with_initial_value_and_increment_throws_IAE_if_increment_is_less_than_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("increment must be > 0");
+
+ new AlwaysIncreasingSystem2(10, -66);
+ }
+
+ @Test
+ public void constructor_with_increment_throws_IAE_if_increment_is_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("increment must be > 0");
+
+ new AlwaysIncreasingSystem2(0);
+ }
+
+ @Test
+ public void constructor_with_increment_throws_IAE_if_increment_is_less_than_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("increment must be > 0");
+
+ new AlwaysIncreasingSystem2(-20);
+ }
+
private void verifyValuesReturnedByNow(AlwaysIncreasingSystem2 underTest, @Nullable Long initialValue, int increment) {
long previousValue = -1;
for (int i = 0; i < 333; i++) {