aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldTest.java20
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodTest.java31
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/RangeDistributionBuilderTest.java58
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java40
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/SonarUpdateTest.java24
5 files changed, 88 insertions, 85 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldTest.java
index 881cb96dab1..36586f6dd28 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldTest.java
@@ -21,9 +21,7 @@ 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.assertTrue;
+import static org.fest.assertions.Assertions.assertThat;
public class AsmFieldTest {
@@ -31,16 +29,16 @@ public class AsmFieldTest {
private AsmClass numberClass = new AsmClass("java/lang/Number");
@Test
- public void testHashCode() {
- assertTrue(new AsmField(stringClass, "firstField").equals(new AsmField(stringClass, "firstField")));
- assertFalse(new AsmField(stringClass, "firstField").equals(new AsmField(stringClass, "secondField")));
- assertFalse(new AsmField(stringClass, "firstField").equals(new AsmField(numberClass, "firstField")));
+ public void testEquals() {
+ assertThat(new AsmField(stringClass, "firstField")).isEqualTo(new AsmField(stringClass, "firstField"));
+ assertThat(new AsmField(stringClass, "firstField")).isNotEqualTo(new AsmField(stringClass, "secondField"));
+ assertThat(new AsmField(stringClass, "firstField")).isNotEqualTo(new AsmField(numberClass, "firstField"));
}
@Test
- public void testEquals() {
- assertEquals(new AsmField(stringClass, "firstField").hashCode(), new AsmField(stringClass, "firstField").hashCode());
- assertFalse(new AsmField(stringClass, "firstField").hashCode() == new AsmField(stringClass, "secondField").hashCode());
- assertFalse(new AsmField(stringClass, "firstField").hashCode() == new AsmField(numberClass, "firstField").hashCode());
+ public void testHashCode() {
+ assertThat(new AsmField(stringClass, "firstField").hashCode()).isEqualTo(new AsmField(stringClass, "firstField").hashCode());
+ assertThat(new AsmField(stringClass, "firstField").hashCode()).isNotEqualTo(new AsmField(stringClass, "secondField").hashCode());
+ assertThat(new AsmField(stringClass, "firstField").hashCode()).isNotEqualTo(new AsmField(numberClass, "firstField").hashCode());
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodTest.java
index ace87024eab..e35bd1d409f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodTest.java
@@ -24,8 +24,13 @@ import org.junit.Test;
import org.sonar.java.ast.SquidTestUtils;
import org.sonar.java.bytecode.ClassLoaderBuilder;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
public class AsmMethodTest {
@@ -38,7 +43,7 @@ public class AsmMethodTest {
AsmClassProvider asmClassProvider = new AsmClassProviderImpl(ClassLoaderBuilder.create(SquidTestUtils.getFile("/bytecode/bin/")));
javaBean = asmClassProvider.getClass("properties/JavaBean");
}
-
+
@Test
public void testAsmMethod() {
AsmMethod method = new AsmMethod(new AsmClass("java/lang/String"), "toString()Ljava/lang/String;");
@@ -46,19 +51,19 @@ public class AsmMethodTest {
}
@Test
- public void testHashCode() {
- assertTrue(new AsmMethod(stringClass, "firstMethod()V").equals(new AsmMethod(stringClass, "firstMethod()V")));
- assertFalse(new AsmMethod(stringClass, "firstMethod()V").equals(new AsmMethod(stringClass, "secondMethod()V")));
- assertFalse(new AsmMethod(stringClass, "firstMethod()V").equals(new AsmMethod(numberClass, "firstMethod()V")));
+ public void testEquals() {
+ assertThat(new AsmMethod(stringClass, "firstMethod()V")).isEqualTo(new AsmMethod(stringClass, "firstMethod()V"));
+ assertThat(new AsmMethod(stringClass, "firstMethod()V")).isNotEqualTo(new AsmMethod(stringClass, "secondMethod()V"));
+ assertThat(new AsmMethod(stringClass, "firstMethod()V")).isNotEqualTo(new AsmMethod(numberClass, "firstMethod()V"));
}
@Test
- public void testEquals() {
- assertEquals(new AsmMethod(stringClass, "firstMethod()V").hashCode(), new AsmMethod(stringClass, "firstMethod()V").hashCode());
- assertFalse(new AsmMethod(stringClass, "firstMethod()V").hashCode() == new AsmMethod(stringClass, "secondMethod()V").hashCode());
- assertFalse(new AsmMethod(stringClass, "firstMethod()V").hashCode() == new AsmMethod(numberClass, "firstMethod()V").hashCode());
+ public void testHashCode() {
+ assertThat(new AsmMethod(stringClass, "firstMethod()V").hashCode()).isEqualTo(new AsmMethod(stringClass, "firstMethod()V").hashCode());
+ assertThat(new AsmMethod(stringClass, "firstMethod()V").hashCode()).isNotEqualTo(new AsmMethod(stringClass, "secondMethod()V").hashCode());
+ assertThat(new AsmMethod(stringClass, "firstMethod()V").hashCode()).isNotEqualTo(new AsmMethod(numberClass, "firstMethod()V").hashCode());
}
-
+
@Test
public void testIsAccessor() {
assertTrue(javaBean.getMethod("getName()Ljava/lang/String;").isAccessor());
@@ -80,7 +85,7 @@ public class AsmMethodTest {
assertFalse(javaBean.getMethod("recursiveAbsSameIncrementA(I)I").isAccessor());
assertFalse(javaBean.getMethod("recursiveAbsDifferentIncrementA(I)I").isAccessor());
}
-
+
@Test
public void testGetAccessedField() {
assertThat(javaBean.getMethod("getName()Ljava/lang/String;").getAccessedField().getName(), is("name"));
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/RangeDistributionBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/RangeDistributionBuilderTest.java
index 334ddfc5ff8..c54e8e2cf7f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/RangeDistributionBuilderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/RangeDistributionBuilderTest.java
@@ -21,58 +21,58 @@ package org.sonar.api.measures;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class RangeDistributionBuilderTest {
-
+
@Test
public void workOnAnLimitsArrayCopy() {
- Integer[] limits = new Integer[]{4,2,0};
+ Integer[] limits = new Integer[] {4, 2, 0};
RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, limits);
builder.add(3.2).add(2.0).add(6.2).build();
- assertTrue(builder.getBottomLimits() != limits);
- assertThat(limits[0], is(4));
- assertThat(limits[1], is(2));
- assertThat(limits[2], is(0));
+
+ assertThat(builder.getBottomLimits()).isNotSameAs(limits);
+ assertThat(limits[0]).isEqualTo(4);
+ assertThat(limits[1]).isEqualTo(2);
+ assertThat(limits[2]).isEqualTo(0);
}
@Test
public void buildIntegerDistribution() {
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[]{0, 2, 4});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[] {0, 2, 4});
Measure measure = builder
.add(3.2)
.add(2.0)
.add(6.2)
.build();
- assertThat(measure.getData(), is("0=0;2=2;4=1"));
+ assertThat(measure.getData()).isEqualTo("0=0;2=2;4=1");
}
@Test
public void buildDoubleDistribution() {
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Double[]{0.0, 2.0, 4.0});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Double[] {0.0, 2.0, 4.0});
Measure measure = builder
.add(3.2)
.add(2.0)
.add(6.2)
.build();
- assertThat(measure.getData(), is("0=0;2=2;4=1"));
+ assertThat(measure.getData()).isEqualTo("0=0;2=2;4=1");
}
@Test
public void valueLesserThanMinimumIsIgnored() {
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[]{0, 2, 4});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[] {0, 2, 4});
Measure measure = builder
.add(3.2)
.add(2.0)
.add(-3.0)
.build();
- assertThat(measure.getData(), is("0=0;2=2;4=0"));
+ assertThat(measure.getData()).isEqualTo("0=0;2=2;4=0");
}
@Test
@@ -80,30 +80,29 @@ public class RangeDistributionBuilderTest {
Measure measureToAdd = mock(Measure.class);
when(measureToAdd.getData()).thenReturn("0=3;2=5");
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[]{0, 2});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[] {0, 2});
builder.clear();
Measure measure = builder
.add(1)
.add(measureToAdd)
.build();
- assertThat(measure.getData(), is("0=4;2=5"));
+ assertThat(measure.getData()).isEqualTo("0=4;2=5");
}
-
@Test
public void addDistributionMeasureWithDifferentIntLimits() {
Measure measureToAdd = mock(Measure.class);
when(measureToAdd.getData()).thenReturn("0=3;2=5");
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[]{0, 2, 4});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[] {0, 2, 4});
builder.clear();
Measure measure = builder
.add(1)
.add(measureToAdd)
.build();
- assertNull(measure);
+ assertThat(measure).isNull();
}
@Test
@@ -111,13 +110,13 @@ public class RangeDistributionBuilderTest {
Measure measureToAdd = mock(Measure.class);
when(measureToAdd.getData()).thenReturn("0.0=3;3.0=5;6.0=9");
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Double[]{0.0, 2.0, 4.0});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Double[] {0.0, 2.0, 4.0});
builder.clear();
Measure measure = builder
.add(measureToAdd)
.build();
- assertNull(measure);
+ assertThat(measure).isNull();
}
@Test
@@ -135,10 +134,9 @@ public class RangeDistributionBuilderTest {
.add(m2)
.build();
- assertThat(measure.getData(), is("0.5=3;3.5=7;6.5=10"));
+ assertThat(measure.getData()).isEqualTo("0.5=3;3.5=7;6.5=10");
}
-
@Test
public void keepIntRangesWhenMergingDistributions() {
Measure m1 = mock(Measure.class);
@@ -154,26 +152,26 @@ public class RangeDistributionBuilderTest {
.add(m2)
.build();
- assertThat(measure.getData(), is("0=3;3=7;6=10"));
+ assertThat(measure.getData()).isEqualTo("0=3;3=7;6=10");
}
@Test
public void nullIfEmptyData() {
- RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[]{0, 2, 4});
+ RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, new Integer[] {0, 2, 4});
- assertThat(builder.isEmpty(), is(true));
+ assertThat(builder.isEmpty()).isTrue();
Measure measure = builder.build(false);
- assertNull(measure);
+ assertThat(measure).isNull();
measure = builder.build(true);
- assertThat(measure.getData(), is("0=0;2=0;4=0"));
+ assertThat(measure.getData()).isEqualTo("0=0;2=0;4=0");
}
@Test
public void aggregateEmptyDistribution() {
RangeDistributionBuilder builder = new RangeDistributionBuilder(CoreMetrics.LCOM4_DISTRIBUTION);
- builder.add(new Measure(CoreMetrics.LCOM4_DISTRIBUTION, (String)null));
+ builder.add(new Measure(CoreMetrics.LCOM4_DISTRIBUTION, (String) null));
Measure distribution = builder.build();
- assertThat(distribution.getData(), is(""));
+ assertThat(distribution.getData()).isEmpty();
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
index db6f03b1106..0c3a8293b03 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
@@ -24,8 +24,7 @@ import org.sonar.api.Property;
import org.sonar.api.config.PropertyDefinitions;
import static junit.framework.Assert.assertTrue;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class ComponentContainerTest {
@@ -33,7 +32,8 @@ public class ComponentContainerTest {
@Test
public void shouldRegisterItself() {
ComponentContainer container = new ComponentContainer();
- assertTrue(container.getComponentByType(ComponentContainer.class) == container);
+
+ assertThat(container.getComponentByType(ComponentContainer.class)).isSameAs(container);
}
@Test
@@ -42,11 +42,11 @@ public class ComponentContainerTest {
container.addSingleton(StartableComponent.class);
container.startComponents();
- assertThat(container.getComponentByType(StartableComponent.class).started, is(true));
- assertThat(container.getComponentByType(StartableComponent.class).stopped, is(false));
+ assertThat(container.getComponentByType(StartableComponent.class).started).isTrue();
+ assertThat(container.getComponentByType(StartableComponent.class).stopped).isFalse();
container.stopComponents();
- assertThat(container.getComponentByType(StartableComponent.class).stopped, is(true));
+ assertThat(container.getComponentByType(StartableComponent.class).stopped).isTrue();
}
@Test
@@ -58,12 +58,12 @@ public class ComponentContainerTest {
child.addSingleton(StartableComponent.class);
child.startComponents();
- assertTrue(child.getParent() == parent);
- assertTrue(parent.getChild() == child);
- assertTrue(child.getComponentByType(ComponentContainer.class) == child);
- assertTrue(parent.getComponentByType(ComponentContainer.class) == parent);
- assertThat(child.getComponentByType(StartableComponent.class), notNullValue());
- assertThat(parent.getComponentByType(StartableComponent.class), nullValue());
+ assertThat(child.getParent()).isSameAs(parent);
+ assertThat(parent.getChild()).isSameAs(child);
+ assertThat(child.getComponentByType(ComponentContainer.class)).isSameAs(child);
+ assertThat(parent.getComponentByType(ComponentContainer.class)).isSameAs(parent);
+ assertThat(child.getComponentByType(StartableComponent.class)).isNotNull();
+ assertThat(parent.getComponentByType(StartableComponent.class)).isNull();
parent.stopComponents();
}
@@ -74,10 +74,10 @@ public class ComponentContainerTest {
parent.startComponents();
ComponentContainer child = parent.createChild();
- assertTrue(parent.getChild() == child);
+ assertThat(parent.getChild()).isSameAs(child);
parent.removeChild();
- assertThat(parent.getChild(), nullValue());
+ assertThat(parent.getChild()).isNull();
}
@Test
@@ -102,8 +102,8 @@ public class ComponentContainerTest {
container.addSingleton(ComponentWithProperty.class);
PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);
- assertThat(propertyDefinitions.get("foo"), notNullValue());
- assertThat(propertyDefinitions.get("foo").getDefaultValue(), is("bar"));
+ assertThat(propertyDefinitions.get("foo")).isNotNull();
+ assertThat(propertyDefinitions.get("foo").getDefaultValue()).isEqualTo("bar");
}
@Test
@@ -113,8 +113,8 @@ public class ComponentContainerTest {
container.declareExtension(plugin, ComponentWithProperty.class);
PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);
- assertThat(propertyDefinitions.get("foo"), notNullValue());
- assertThat(container.getComponentByType(ComponentWithProperty.class), nullValue());
+ assertThat(propertyDefinitions.get("foo")).isNotNull();
+ assertThat(container.getComponentByType(ComponentWithProperty.class)).isNull();
}
@Test
@@ -124,8 +124,8 @@ public class ComponentContainerTest {
container.addExtension(plugin, ComponentWithProperty.class);
PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);
- assertThat(propertyDefinitions.get("foo"), notNullValue());
- assertThat(container.getComponentByType(ComponentWithProperty.class), notNullValue());
+ assertThat(propertyDefinitions.get("foo")).isNotNull();
+ assertThat(container.getComponentByType(ComponentWithProperty.class)).isNotNull();
}
public static class StartableComponent {
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/SonarUpdateTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/SonarUpdateTest.java
index 571dad3e4b4..ea93b1cfca0 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/SonarUpdateTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/SonarUpdateTest.java
@@ -25,8 +25,7 @@ import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.Sonar;
import org.sonar.updatecenter.common.Version;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.fest.assertions.Assertions.assertThat;
public class SonarUpdateTest {
@@ -34,26 +33,29 @@ public class SonarUpdateTest {
public void incompatibleUpdateIfSomePluginsAreIncompatible() {
SonarUpdate update = new SonarUpdate(new Release(new Sonar(), "2.3"));
update.addIncompatiblePlugin(new Plugin("old"));
- assertTrue(update.isIncompatible());
- assertTrue(update.hasWarnings());
- assertFalse(update.requiresPluginUpgrades());
+
+ assertThat(update.isIncompatible()).isTrue();
+ assertThat(update.hasWarnings()).isTrue();
+ assertThat(update.requiresPluginUpgrades()).isFalse();
}
@Test
public void incompatibleUpdateIfRequiredPluginUpgrades() {
SonarUpdate update = new SonarUpdate(new Release(new Sonar(), "2.3"));
update.addPluginToUpgrade(new Release(new Plugin("old"), Version.create("0.2")));
- assertFalse(update.isIncompatible());
- assertTrue(update.hasWarnings());
- assertTrue(update.requiresPluginUpgrades());
+
+ assertThat(update.isIncompatible()).isFalse();
+ assertThat(update.hasWarnings()).isTrue();
+ assertThat(update.requiresPluginUpgrades()).isTrue();
}
@Test
public void equals() {
SonarUpdate update1 = new SonarUpdate(new Release(new Sonar(), "2.2"));
SonarUpdate update2 = new SonarUpdate(new Release(new Sonar(), "2.3"));
- assertTrue(update1.equals(update1));
- assertTrue(update1.equals(new SonarUpdate(new Release(new Sonar(), "2.2"))));
- assertFalse(update1.equals(update2));
+
+ assertThat(update1).isEqualTo(update1);
+ assertThat(update1).isEqualTo(new SonarUpdate(new Release(new Sonar(), "2.2")));
+ assertThat(update1).isNotEqualTo(update2);
}
}