diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-26 13:19:19 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-26 13:19:19 +0100 |
commit | 679bc82d5c453bccdf2eb8f51c410cda1773165a (patch) | |
tree | bc13cdeae8440a1764247de177c51112fdd39857 /sonar-plugin-api/src/test | |
parent | 55a9be1fa31394aec3093bc27cd9c501f0f0cc60 (diff) | |
download | sonarqube-679bc82d5c453bccdf2eb8f51c410cda1773165a.tar.gz sonarqube-679bc82d5c453bccdf2eb8f51c410cda1773165a.zip |
Improve duration format validation
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java | 4 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java | 34 |
2 files changed, 33 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java index 6223fc8d17e..f4c28fe2737 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/debt/DefaultDebtRemediationFunctionTest.java @@ -20,7 +20,6 @@ package org.sonar.api.server.debt; -import org.junit.Ignore; import org.junit.Test; import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction; @@ -147,14 +146,13 @@ public class DefaultDebtRemediationFunctionTest { .isEqualTo("DebtRemediationFunction{type=LINEAR_OFFSET, factor=10h, offset=5min}"); } - @Ignore @Test public void fail_if_bad_factor_format() { try { new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "foo", null); fail(); } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("TODO"); + assertThat(e).hasMessage("Invalid factor: foo"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java index f75ec12f392..ebddda39ef8 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DurationTest.java @@ -51,14 +51,14 @@ public class DurationTest { @Test public void decode() throws Exception { assertThat(Duration.decode(" 15 d 26 h 42min ", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES + 26 * ONE_HOUR_IN_MINUTES + 42 * ONE_MINUTE)); - assertThat(Duration.decode("26h15d42min", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES + 26 * ONE_HOUR_IN_MINUTES + 42 * ONE_MINUTE)); + assertThat(Duration.decode("15d26h42min", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES + 26 * ONE_HOUR_IN_MINUTES + 42 * ONE_MINUTE)); assertThat(Duration.decode("26h", HOURS_IN_DAY)).isEqualTo(Duration.create(26 * ONE_HOUR_IN_MINUTES)); assertThat(Duration.decode("15d", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES)); assertThat(Duration.decode("42min", HOURS_IN_DAY)).isEqualTo(Duration.create(42 * ONE_MINUTE)); } @Test - public void fail_to_decode_if_not_number() throws Exception { + public void fail_to_decode_if_unit_with_invalid_number() throws Exception { try { Duration.decode("Xd", HOURS_IN_DAY); fail(); @@ -68,6 +68,36 @@ public class DurationTest { } @Test + public void fail_to_decode_if_no_valid_duration() throws Exception { + try { + Duration.decode("foo", HOURS_IN_DAY); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Duration 'foo' is invalid, it should use the following sample format : 2d 10h 15min"); + } + } + + @Test + public void fail_to_decode_if_only_number() throws Exception { + try { + Duration.decode("15", HOURS_IN_DAY); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Duration '15' is invalid, it should use the following sample format : 2d 10h 15min"); + } + } + + @Test + public void fail_to_decode_if_valid_unit_with_invalid_duration() throws Exception { + try { + Duration.decode("15min foo", HOURS_IN_DAY); + fail(); + } catch (Exception e) { + assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Duration '15min foo' is invalid, it should use the following sample format : 2d 10h 15min"); + } + } + + @Test public void is_greater_than() throws Exception { assertThat(Duration.decode("1h", HOURS_IN_DAY).isGreaterThan(Duration.decode("1min", HOURS_IN_DAY))).isTrue(); assertThat(Duration.decode("1min", HOURS_IN_DAY).isGreaterThan(Duration.decode("1d", HOURS_IN_DAY))).isFalse(); |