Took the opportunity to migrate some tests to FestAssert.
Also removed some duplication
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
+}
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());
}
}
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
*/
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();
+ }
}
<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
*/
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);
}
}
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 {
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
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
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);
}
-
-
}
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 {
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
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 {
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
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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;
@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
assertEquals(file, method.getAncestor(SourceFile.class));
}
-
@Test
public void testHasAmongParents() {
assertTrue(cla.hasAmongParents(prj));