]> source.dussan.org Git - sonarqube.git/commitdiff
Remove some violations on unit tests
authorDavid Gageot <david@gageot.net>
Thu, 14 Jun 2012 12:15:47 +0000 (14:15 +0200)
committerDavid Gageot <david@gageot.net>
Thu, 14 Jun 2012 15:31:56 +0000 (17:31 +0200)
Took the opportunity to migrate some tests to FestAssert.
Also removed some duplication

plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyAnalyserTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassTest.java
sonar-duplications/pom.xml
sonar-duplications/src/test/java/org/sonar/duplications/utils/FastStringComparatorTest.java
sonar-graph/pom.xml
sonar-graph/src/test/java/org/sonar/graph/CycleTest.java
sonar-plugin-api/src/test/java/org/sonar/api/qualitymodel/CharacteristicTest.java
sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java
sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java
sonar-squid/pom.xml
sonar-squid/src/test/java/org/sonar/squid/api/SourceCodeTest.java

index 5a285805a9a62e93705509669e320869f9614696..9d8011f5e7fe3f2e4e42d3b874735ba14c4b9dcd 100644 (file)
@@ -22,111 +22,107 @@ package org.sonar.plugins.core.timemachine;
 import org.junit.Test;
 
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
 
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.*;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class TendencyAnalyserTest {
-  private TendencyAnalyser analyser = new TendencyAnalyser();
-
-  private List<Double> getValues(Double[] array) {
-    return Arrays.asList(array);
+  static TendencyAnalyser.SlopeData analyse(Double... values) {
+    return new TendencyAnalyser().analyse(Arrays.asList(values));
   }
 
-
-  protected void assertBetween(String typeLabel, Double value, Double min, Double max) {
-    assertTrue(typeLabel + " " + value + "<" + min, value >= min);
-    assertTrue(typeLabel + "=" + value + ">" + max, value <= max);
+  static Integer analyseLevel(Double... values) {
+    return new TendencyAnalyser().analyseLevel(Arrays.asList(values));
   }
 
   @Test
   public void testNoData() {
-    assertThat(analyser.analyse(Collections.<Double>emptyList()), nullValue());
+    TendencyAnalyser.SlopeData slopeData = analyse();
+
+    assertThat(slopeData).isNull();
   }
 
   @Test
   public void testNotEnoughData() {
-    assertThat(analyser.analyseLevel(Arrays.asList(10.0)), nullValue());
+    assertThat(analyseLevel(10.0)).isNull();
   }
 
   @Test
   public void testTendencyOnThreeDays() {
-    Double[] doubles = new Double[]{10.0, null, 9.9};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), -0.5, 0.5);
-    assertEquals(TendencyAnalyser.TENDENCY_NEUTRAL, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(10.0, null, 9.9);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(-0.5).isLessThan(0.5);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_NEUTRAL);
   }
 
   @Test
   public void testTendencyOnTwoZeroDays() {
-    Double[] doubles = new Double[]{0.0, 0.0};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), -0.0, 0.0);
-    assertEquals(TendencyAnalyser.TENDENCY_NEUTRAL, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(0.0, 0.0);
+
+    assertThat(slopeData.getSlope()).isZero();
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_NEUTRAL);
   }
 
   @Test
   public void testTendencyOnThreeZeroDays() {
-    Double[] doubles = new Double[]{0.0, 0.0, 0.0};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), -0.0, 0.0);
-    assertEquals(TendencyAnalyser.TENDENCY_NEUTRAL, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(0.0, 0.0, 0.0);
+
+    assertThat(slopeData.getSlope()).isZero();
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_NEUTRAL);
   }
 
   @Test
   public void testBigDownOnThreeDays() {
-    Double[] doubles = new Double[]{90.0, 91.0, 50.0};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertTrue("slope", slopeData.getSlope() < -2.0);
-    assertEquals(TendencyAnalyser.TENDENCY_BIG_DOWN, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(90.0, 91.0, 50.0);
+
+    assertThat(slopeData.getSlope()).isLessThan(-2.0);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_BIG_DOWN);
   }
 
   @Test
   public void testFlatTendency() {
-    Double[] doubles = new Double[]{10.0, 10.2, 9.9};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), -0.5, 0.5);
-    assertEquals(TendencyAnalyser.TENDENCY_NEUTRAL, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(10.0, 10.2, 9.9);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(-0.5).isLessThan(0.5);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_NEUTRAL);
   }
 
   @Test
   public void testFlatTendencyWithPeak() {
-    Double[] doubles = new Double[]{10.0, 15.0, 10.0};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), -0.5, 0.5);
-    assertEquals(TendencyAnalyser.TENDENCY_NEUTRAL, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(10.0, 15.0, 10.0);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(-0.5).isLessThan(0.5);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_NEUTRAL);
   }
 
   @Test
   public void testBigUpTendencyOnThreeValues() {
-    Double[] doubles = new Double[]{10.0, 12.0, 15.5};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), 2.5, 3.0);
-    assertEquals(TendencyAnalyser.TENDENCY_BIG_UP, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(10.0, 12.0, 15.5);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(2.5).isLessThan(3.0);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_BIG_UP);
   }
 
   @Test
   public void testBigUpTendencyOnTenValues() {
-    Double[] doubles = new Double[]{45.0, 60.0, 57.0, 65.0, 58.0, 68.0, 59.0, 66.0, 76.0, 80.0};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), 2.5, 3.0);
-    assertEquals(TendencyAnalyser.TENDENCY_BIG_UP, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(45.0, 60.0, 57.0, 65.0, 58.0, 68.0, 59.0, 66.0, 76.0, 80.0);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(2.5).isLessThan(3.0);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_BIG_UP);
   }
 
   @Test
   public void testMediumUpTendency() {
-    Double[] doubles = new Double[]{5.0, 4.5, 5.1, 5.5, 5.3, 6.4, 6.3, 6.6, 6.8, 6.5};
-    TendencyAnalyser.SlopeData slopeData = analyser.analyse(getValues(doubles));
-    assertBetween("slope", slopeData.getSlope(), 0.0, 1.0);
-    assertEquals(TendencyAnalyser.TENDENCY_UP, slopeData.getLevel());
+    TendencyAnalyser.SlopeData slopeData = analyse(5.0, 4.5, 5.1, 5.5, 5.3, 6.4, 6.3, 6.6, 6.8, 6.5);
+
+    assertThat(slopeData.getSlope()).isGreaterThan(0.0).isLessThan(1.0);
+    assertThat(slopeData.getLevel()).isEqualTo(TendencyAnalyser.TENDENCY_UP);
   }
 
   @Test
   public void testAsymetricAlgorithm() {
-    TendencyAnalyser.SlopeData slopeData1 = analyser.analyse(getValues(new Double[]{45.0, 47.0, 95.0}));
-    TendencyAnalyser.SlopeData slopeData2 = analyser.analyse(getValues(new Double[]{95.0, 45.0, 47.0}));
-    assertTrue(slopeData1.getSlope() != slopeData2.getSlope());
+    TendencyAnalyser.SlopeData slopeData1 = analyse(45.0, 47.0, 95.0);
+    TendencyAnalyser.SlopeData slopeData2 = analyse(95.0, 45.0, 47.0);
+
+    assertThat(slopeData1.getSlope()).isNotEqualTo(slopeData2.getSlope());
   }
-}
\ No newline at end of file
+}
index 6de6bd92ecb7bf5aaf3b16bc4c1cca8ece62c391..4c6599e4ea6a00f324a8af1db090087c970542b8 100644 (file)
@@ -21,34 +21,33 @@ package org.sonar.java.bytecode.asm;
 
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class AsmClassTest {
 
   @Test
   public void testGetFieldOrCreateIt() {
     AsmClass asmClass = new AsmClass("java/lang/String");
-    assertNull(asmClass.getField("internalString"));
-    assertNotNull(asmClass.getFieldOrCreateIt("internalString"));
-    assertNotNull(asmClass.getField("internalString"));
+
+    assertThat(asmClass.getField("internalString")).isNull();
+    assertThat(asmClass.getFieldOrCreateIt("internalString")).isNotNull();
+    assertThat(asmClass.getField("internalString")).isNotNull();
   }
 
   @Test
   public void testGetMethoddOrCreateIt() {
     AsmClass asmClass = new AsmClass("java/lang/String");
-    assertNull(asmClass.getMethod("toString()Ljava/lang/String;"));
-    assertNotNull(asmClass.getMethodOrCreateIt("toString()Ljava/lang/String;"));
-    assertNotNull(asmClass.getMethod("toString()Ljava/lang/String;"));
+
+    assertThat(asmClass.getMethod("toString()Ljava/lang/String;")).isNull();
+    assertThat(asmClass.getMethodOrCreateIt("toString()Ljava/lang/String;")).isNotNull();
+    assertThat(asmClass.getMethod("toString()Ljava/lang/String;")).isNotNull();
   }
 
   @Test
   public void testEqualsAndHashcode() {
-    assertEquals(new AsmClass("java/lang/String"), new AsmClass("java/lang/String"));
-    assertEquals(new AsmClass("java/lang/String").hashCode(), new AsmClass("java/lang/String").hashCode());
-    assertFalse(new AsmClass("java/lang/String").equals(new AsmClass("java/lang/Number")));
-    assertFalse(new AsmClass("java/lang/String").hashCode() == new AsmClass("java/lang/Number").hashCode());
+    assertThat(new AsmClass("java/lang/String")).isEqualTo(new AsmClass("java/lang/String"));
+    assertThat(new AsmClass("java/lang/String").hashCode()).isEqualTo(new AsmClass("java/lang/String").hashCode());
+    assertThat(new AsmClass("java/lang/String")).isNotEqualTo(new AsmClass("java/lang/Number"));
+    assertThat(new AsmClass("java/lang/String").hashCode()).isNotEqualTo(new AsmClass("java/lang/Number").hashCode());
   }
 }
index 1b822ab9df4d01eb89174378c7de8b594531fff8..c5cd45c674258810f090b4f5b6151e407f05f105 100644 (file)
       <artifactId>logback-classic</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
index 6da568e4b4ec78f5257dce6668c8e85112206173..bc79187bec1830dc53992a624ecb20521634e492 100644 (file)
  */
 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();
+  }
 }
index 48a57076b773258cd6fc917544aa5b441df47454..0b64f3ed9af16c14521c64eb1e70a80ad1f07112 100644 (file)
       <artifactId>hamcrest-all</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file
index edf9d2905bf3e6c9c4f2d462e08ff8d907b949c1..bc823e9d8f86af9f9759a6ff9c88017c517a65f0 100644 (file)
  */
 package org.sonar.graph;
 
-import java.util.Arrays;
-
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.List;
 
-public class CycleTest {
+import static org.fest.assertions.Assertions.assertThat;
 
-  private Edge[] AB_Cycle = { new StringEdge("A", "B"), new StringEdge("B", "A") };
-  private Edge[] BA_Cycle = { new StringEdge("B", "A"), new StringEdge("A", "B") };
-  private Edge[] ABC_Cycle = { new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "A") };
-  private Edge[] HIJ_Cycle = { new StringEdge("H", "I"), new StringEdge("I", "J"), new StringEdge("J", "H") };
-  private Edge[] ABCD_Cycle = { new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A") };
-  private Edge[] BCDA_Cycle = { new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"), new StringEdge("A", "B"), };
+public class CycleTest {
+  static List<Edge> AB_BA = list(new StringEdge("A", "B"), new StringEdge("B", "A"));
+  static List<Edge> BA_AB = list(new StringEdge("B", "A"), new StringEdge("A", "B"));
+  static List<Edge> AB_BC_CA = list(new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "A"));
+  static List<Edge> HI_IJ_JH = list(new StringEdge("H", "I"), new StringEdge("I", "J"), new StringEdge("J", "H"));
+  static List<Edge> AB_BC_CD_DA = list(new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"));
+  static List<Edge> BC_CD_DA_AB = list(new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"), new StringEdge("A", "B"));
 
   @Test
   public void testHashCode() {
-    assertTrue(new Cycle(Arrays.asList(AB_Cycle)).hashCode() == new Cycle(Arrays.asList(BA_Cycle)).hashCode());
-    assertTrue(new Cycle(Arrays.asList(BCDA_Cycle)).hashCode() == new Cycle(Arrays.asList(ABCD_Cycle)).hashCode());
-    assertFalse(new Cycle(Arrays.asList(AB_Cycle)).hashCode() == new Cycle(Arrays.asList(ABC_Cycle)).hashCode());
+    assertThat(new Cycle(AB_BA).hashCode()).isEqualTo(new Cycle(BA_AB).hashCode());
+    assertThat(new Cycle(BC_CD_DA_AB).hashCode()).isEqualTo(new Cycle(AB_BC_CD_DA).hashCode());
+    assertThat(new Cycle(AB_BA).hashCode()).isNotEqualTo(new Cycle(AB_BC_CA).hashCode());
   }
 
   @Test
   public void testContains() {
-    assertTrue(new Cycle(Arrays.asList(ABCD_Cycle)).contains(new StringEdge("B", "C")));
+    assertThat(new Cycle(AB_BC_CD_DA).contains(new StringEdge("B", "C"))).isTrue();
   }
 
   @Test
   public void testEqualsObject() {
-    assertEquals(new Cycle(Arrays.asList(AB_Cycle)), new Cycle(Arrays.asList(BA_Cycle)));
-    assertEquals(new Cycle(Arrays.asList(BCDA_Cycle)), new Cycle(Arrays.asList(ABCD_Cycle)));
-    assertFalse(new Cycle(Arrays.asList(BCDA_Cycle)).equals(new Cycle(Arrays.asList(AB_Cycle))));
-    assertFalse(new Cycle(Arrays.asList(ABC_Cycle)).equals(new Cycle(Arrays.asList(HIJ_Cycle))));
+    assertThat(new Cycle(AB_BA)).isEqualTo(new Cycle(BA_AB));
+    assertThat(new Cycle(BC_CD_DA_AB)).isEqualTo(new Cycle(AB_BC_CD_DA));
+  }
+
+  @Test
+  public void testNotEqualsObject() {
+    assertThat(new Cycle(BC_CD_DA_AB)).isNotEqualTo(new Cycle(AB_BA));
+    assertThat(new Cycle(AB_BC_CA)).isNotEqualTo(new Cycle(HI_IJ_JH));
+  }
+
+  static List<Edge> list(StringEdge... edges) {
+    return Arrays.<Edge> asList(edges);
   }
 }
index 5e9c0446dc986066cf8f535c87e9b01062e46881..b58d0bdd18ad57b032c45cc1bf7469d57e7c0f35 100644 (file)
@@ -21,11 +21,7 @@ package org.sonar.api.qualitymodel;
 
 import org.junit.Test;
 
-import static junit.framework.Assert.assertTrue;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class CharacteristicTest {
 
@@ -34,12 +30,12 @@ public class CharacteristicTest {
     Characteristic characteristic = Characteristic.create();
     characteristic.setProperty("foo", "bar");
 
-    assertThat(characteristic.getProperty("foo"), notNullValue());
-    assertThat(characteristic.getPropertyTextValue("foo", null), is("bar"));
-    assertThat(characteristic.getPropertyValue("foo", null), nullValue());
+    assertThat(characteristic.getProperty("foo")).isNotNull();
+    assertThat(characteristic.getPropertyTextValue("foo", null)).isEqualTo("bar");
+    assertThat(characteristic.getPropertyValue("foo", null)).isNull();
 
-    assertThat(characteristic.getProperty("unknown"), nullValue());
-    assertThat(characteristic.getPropertyTextValue("unknown", null), nullValue());
+    assertThat(characteristic.getProperty("unknown")).isNull();
+    assertThat(characteristic.getPropertyTextValue("unknown", null)).isNull();
   }
 
   @Test
@@ -47,9 +43,9 @@ public class CharacteristicTest {
     Characteristic characteristic = Characteristic.create();
     characteristic.setProperty("foo", 3.1);
 
-    assertThat(characteristic.getProperty("foo"), notNullValue());
-    assertThat(characteristic.getPropertyValue("foo", null), is(3.1));
-    assertThat(characteristic.getPropertyTextValue("foo", null), nullValue());
+    assertThat(characteristic.getProperty("foo")).isNotNull();
+    assertThat(characteristic.getPropertyValue("foo", null)).isEqualTo(3.1);
+    assertThat(characteristic.getPropertyTextValue("foo", null)).isNull();
   }
 
   @Test
@@ -58,28 +54,27 @@ public class CharacteristicTest {
     characteristic.addProperty(CharacteristicProperty.create("foo"));
 
     CharacteristicProperty property = characteristic.getProperty("foo");
-    assertThat(property, notNullValue());
-    assertTrue(property.getCharacteristic()==characteristic);
+    assertThat(property).isNotNull();
+    assertThat(property.getCharacteristic()).isSameAs(characteristic);
   }
 
   @Test
   public void shouldCreateByName() {
     Characteristic characteristic = Characteristic.createByName("Foo");
-    assertThat(characteristic.getKey(), is("FOO"));
-    assertThat(characteristic.getName(), is("Foo"));
+
+    assertThat(characteristic.getKey()).isEqualTo("FOO");
+    assertThat(characteristic.getName()).isEqualTo("Foo");
   }
 
   @Test
   public void shouldReturnDefaultValues() {
     Characteristic characteristic = Characteristic.create();
-    characteristic.setProperty("foo", (String)null);
-    characteristic.setProperty("bar", (Double)null);
+    characteristic.setProperty("foo", (String) null);
+    characteristic.setProperty("bar", (Double) null);
 
-    assertThat(characteristic.getPropertyTextValue("foo", "foodef"), is("foodef"));
-    assertThat(characteristic.getPropertyTextValue("other", "otherdef"), is("otherdef"));
-    assertThat(characteristic.getPropertyValue("bar", 3.14), is(3.14));
-    assertThat(characteristic.getPropertyValue("other", 3.14), is(3.14));
+    assertThat(characteristic.getPropertyTextValue("foo", "foodef")).isEqualTo("foodef");
+    assertThat(characteristic.getPropertyTextValue("other", "otherdef")).isEqualTo("otherdef");
+    assertThat(characteristic.getPropertyValue("bar", 3.14)).isEqualTo(3.14);
+    assertThat(characteristic.getPropertyValue("other", 3.14)).isEqualTo(3.14);
   }
-
-  
 }
index 8533b26b7b3172898f25466a968406ce9696ba87..5cd0cb6b63df21930bcd760ca1999e779883d34a 100644 (file)
@@ -25,17 +25,25 @@ import org.junit.Test;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.profiles.Alert;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.*;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.ActiveRuleParam;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleParam;
+import org.sonar.api.rules.RulePriority;
 import org.sonar.jpa.test.AbstractDbUnitTestCase;
 import org.sonar.test.TestUtils;
 
 import java.io.IOException;
 import java.util.Arrays;
 
+import static org.fest.assertions.Assertions.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.collection.IsCollectionContaining.hasItem;
 import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 
 public class ProfilesBackupTest extends AbstractDbUnitTestCase {
 
@@ -57,8 +65,8 @@ public class ProfilesBackupTest extends AbstractDbUnitTestCase {
     ProfilesBackup profilesBackup = new ProfilesBackup(Arrays.asList(profileProvided));
     profilesBackup.exportXml(sonarConfig);
 
-    assertFalse(sonarConfig.getProfiles().iterator().next() == profileProvided);
-    assertEquals(sonarConfig.getProfiles().iterator().next().getName(), "provided");
+    assertThat(sonarConfig.getProfiles().iterator().next()).isNotSameAs(profileProvided);
+    assertThat(sonarConfig.getProfiles().iterator().next().getName()).isEqualTo("provided");
   }
 
   @Test
index 5e3f3bada92c5de4bd5705afc0969bd811c289b8..49fca44c771a4435cc529b7cdc946cd5d6519825 100644 (file)
@@ -29,11 +29,11 @@ import org.sonar.jpa.test.AbstractDbUnitTestCase;
 
 import java.util.Arrays;
 
+import static org.fest.assertions.Assertions.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 
 public class RulesBackupTest extends AbstractDbUnitTestCase {
 
@@ -65,8 +65,7 @@ public class RulesBackupTest extends AbstractDbUnitTestCase {
     RulesBackup rulesBackup = new RulesBackup(Arrays.asList(userRule));
     rulesBackup.exportXml(sonarConfig);
 
-    assertThat(sonarConfig.getRules().size(), is(1));
-    assertTrue(sonarConfig.getRules().iterator().next() == userRule);
+    assertThat(sonarConfig.getRules()).containsOnly(userRule);
   }
 
   @Test
index 133ecbd2988f4d78a867d9c32d7c69059353a0ef..43223a8c387b73035f1a6ae760c3326997d91015 100644 (file)
       <artifactId>hamcrest-all</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
index ea4e916a8ae73ecca54d204de8e1859173decdb0..6e15fb84e8033010a5066e9a57b10d2ea784d965 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.sonar.squid.measures.Measurable;
 import org.sonar.squid.measures.Metric;
 
+import static org.fest.assertions.Assertions.assertThat;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -62,12 +63,13 @@ public class SourceCodeTest {
 
   @Test
   public void testEqualsAndHashCode() {
-    assertFalse((prj.equals(pac)));
-    assertFalse(prj.hashCode() == pac.hashCode());
-    assertFalse(prj.equals(new Object()));
+    assertThat(prj).isNotEqualTo(pac);
+    assertThat(prj.hashCode()).isNotEqualTo(pac.hashCode());
+    assertThat(prj).isNotEqualTo(new Object());
+
     SourceCode samePac = new SourcePackage("org.sonar");
-    assertEquals(pac, samePac);
-    assertEquals(pac.hashCode(), samePac.hashCode());
+    assertThat(pac).isEqualTo(samePac);
+    assertThat(pac.hashCode()).isEqualTo(samePac.hashCode());
   }
 
   @Test
@@ -111,7 +113,6 @@ public class SourceCodeTest {
     assertEquals(file, method.getAncestor(SourceFile.class));
   }
 
-
   @Test
   public void testHasAmongParents() {
     assertTrue(cla.hasAmongParents(prj));