diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-12-07 10:04:13 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-12-07 10:04:13 +0100 |
commit | 6799c6936b4b53f513e6adcd54c81beffb887719 (patch) | |
tree | f2adf60727577f242649eb3af05a12539ea2b55a | |
parent | d9f11d294531fc2c628a27463f29ab5c92af0c90 (diff) | |
download | sonarqube-6799c6936b4b53f513e6adcd54c81beffb887719.tar.gz sonarqube-6799c6936b4b53f513e6adcd54c81beffb887719.zip |
fix quality flaws
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java | 17 | ||||
-rw-r--r-- | sonar-testing-harness/src/main/java/org/sonar/test/ExceptionCauseMatcher.java | 9 |
2 files changed, 24 insertions, 2 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java index 403cf722fff..264fe1629ab 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/period/PeriodTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DAYS; import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; public class PeriodTest { @@ -77,4 +78,20 @@ public class PeriodTest { assertThat(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L).toString()) .isEqualTo("Period{index=1, mode=version, modeParameter=2.3, snapshotDate=1420034400000, snapshotId=10}"); } + + @Test + public void equals_is_done_on_all_fields() { + Period period = new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L); + + assertThat(period).isEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L)); + + assertThat(period).isNotEqualTo(null); + assertThat(period).isNotEqualTo("sdsd"); + assertThat(period).isNotEqualTo(new Period(2, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L)); + assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_DAYS, "2.3", 1420034400000L, 10L)); + assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.4", 1420034400000L, 10L)); + assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 555L, 10L)); + assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 9632554L)); + + } } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/ExceptionCauseMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/ExceptionCauseMatcher.java index 9eaf1d6923c..803e3527180 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/ExceptionCauseMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/ExceptionCauseMatcher.java @@ -64,8 +64,13 @@ public class ExceptionCauseMatcher extends TypeSafeMatcher<Throwable> { @Override protected boolean matchesSafely(Throwable item) { - return item.getClass().isAssignableFrom(type) - && (expectedMessage == null || EXPECT_NO_MESSAGE_CONSTANT.equals(expectedMessage) ? item.getMessage() == null : item.getMessage().contains(expectedMessage)); + if (!item.getClass().isAssignableFrom(type)) { + return false; + } + if (expectedMessage == null) { + return true; + } + return EXPECT_NO_MESSAGE_CONSTANT.equals(expectedMessage) ? item.getMessage() == null : item.getMessage().contains(expectedMessage); } @Override |