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 {
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());
}
}
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 {
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;");
}
@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());
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"));
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
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
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
.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);
.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();
}
}
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 {
@Test
public void shouldRegisterItself() {
ComponentContainer container = new ComponentContainer();
- assertTrue(container.getComponentByType(ComponentContainer.class) == container);
+
+ assertThat(container.getComponentByType(ComponentContainer.class)).isSameAs(container);
}
@Test
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
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();
}
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
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
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
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 {
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 {
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);
}
}