diff options
author | David Gageot <david@gageot.net> | 2012-06-14 14:15:47 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-06-14 17:31:56 +0200 |
commit | 72afb8a3154d4525d9a956b755d2871a4a5c3d9f (patch) | |
tree | 8536dfee94e0b13ab04b5e6fb575dbdc9724c82d /sonar-duplications | |
parent | 1cdea962c00d3106c2e64704fde0068d73a110c0 (diff) | |
download | sonarqube-72afb8a3154d4525d9a956b755d2871a4a5c3d9f.tar.gz sonarqube-72afb8a3154d4525d9a956b755d2871a4a5c3d9f.zip |
Remove some violations on unit tests
Took the opportunity to migrate some tests to FestAssert.
Also removed some duplication
Diffstat (limited to 'sonar-duplications')
-rw-r--r-- | sonar-duplications/pom.xml | 5 | ||||
-rw-r--r-- | sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java | 41 |
2 files changed, 26 insertions, 20 deletions
diff --git a/sonar-duplications/pom.xml b/sonar-duplications/pom.xml index 1b822ab9df4..c5cd45c6742 100644 --- a/sonar-duplications/pom.xml +++ b/sonar-duplications/pom.xml @@ -52,5 +52,10 @@ <artifactId>logback-classic</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.easytesting</groupId> + <artifactId>fest-assert</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java index 6da568e4b4e..bc79187bec1 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java @@ -19,52 +19,53 @@ */ package org.sonar.duplications.utils; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import org.junit.Test; -import org.sonar.duplications.utils.FastStringComparator; + +import static org.fest.assertions.Assertions.assertThat; public class FastStringComparatorTest { + static int compare(String left, String right) { + return FastStringComparator.INSTANCE.compare(left, right); + } @Test public void sameHashCode() { // Next two Strings have same hash code in Java - see http://www.drmaciver.com/2008/07/javalangstringhashcode/ String s1 = "Od"; String s2 = "PE"; - assertTrue("same hash code", s1.hashCode() == s2.hashCode()); - assertThat("s1 < s2", FastStringComparator.INSTANCE.compare(s1, s2), lessThan(0)); - assertThat("s2 > s1", FastStringComparator.INSTANCE.compare(s2, s1), greaterThan(0)); + + assertThat(s1.hashCode()).isEqualTo(s2.hashCode()); + assertThat(compare(s1, s2)).isLessThan(0); + assertThat(compare(s2, s1)).isGreaterThan(0); } @Test public void differentHashCode() { String s1 = "a"; String s2 = "c"; - assertTrue("different hash code", s1.hashCode() != s2.hashCode()); - assertThat("s1 < s2", FastStringComparator.INSTANCE.compare(s1, s2), is(-1)); - assertThat("s2 > s1", FastStringComparator.INSTANCE.compare(s2, s1), is(1)); + + assertThat(s1.hashCode()).isNotEqualTo(s2.hashCode()); + assertThat(compare(s1, s2)).isEqualTo(-1); + assertThat(compare(s2, s1)).isEqualTo(1); } @Test public void sameObject() { String s1 = "a"; String s2 = s1; - assertTrue("same objects", s1 == s2); - assertThat("s1 = s2", FastStringComparator.INSTANCE.compare(s1, s2), is(0)); - assertThat("s2 = s1", FastStringComparator.INSTANCE.compare(s2, s1), is(0)); + + assertThat(s1).isSameAs(s2); + assertThat(compare(s1, s2)).isZero(); + assertThat(compare(s1, s2)).isZero(); } @Test public void sameString() { String s1 = new String("a"); String s2 = new String("a"); - assertTrue("different objects", s1 != s2); - assertThat("s1 = s2", FastStringComparator.INSTANCE.compare(s1, s2), is(0)); - assertThat("s2 = s1", FastStringComparator.INSTANCE.compare(s2, s1), is(0)); - } + assertThat(s1).isNotSameAs(s2); + assertThat(compare(s1, s2)).isZero(); + assertThat(compare(s1, s2)).isZero(); + } } |