]> source.dussan.org Git - sonarqube.git/commitdiff
Replace Junit / Hamcrest by FestAssert
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 21 Jan 2013 10:26:44 +0000 (11:26 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 21 Jan 2013 10:26:55 +0000 (11:26 +0100)
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java

index 6df65a51e61d7448fe8883f46378d292bdb94348..09561017e2ead79eea8e775d08fbfe671551c07e 100644 (file)
@@ -22,52 +22,59 @@ package org.sonar.wsclient.unmarshallers;
 import org.junit.Test;
 import org.sonar.wsclient.services.TimeMachine;
 
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import java.util.Calendar;
+import java.util.Date;
+
+import static org.fest.assertions.Assertions.assertThat;
 
 public class TimeMachineUnmarshallerTest extends UnmarshallerTestCase {
 
   @Test
-  public void testToModel() throws Exception {
+  public void test_to_model() throws Exception {
     TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/timemachine.json"));
 
     // columns
-    assertThat(timeMachine.getColumns().length, is(2));
-    assertThat(timeMachine.getColumns()[0].getIndex(), is(0));
-    assertThat(timeMachine.getColumns()[0].getMetricKey(), is("ncloc"));
-    assertThat(timeMachine.getColumns()[1].getIndex(), is(1));
-    assertThat(timeMachine.getColumns()[1].getMetricKey(), is("coverage"));
+    assertThat(timeMachine.getColumns().length).isEqualTo(2);
+    assertThat(timeMachine.getColumns()[0].getIndex()).isEqualTo(0);
+    assertThat(timeMachine.getColumns()[0].getMetricKey()).isEqualTo("ncloc");
+    assertThat(timeMachine.getColumns()[1].getIndex()).isEqualTo(1);
+    assertThat(timeMachine.getColumns()[1].getMetricKey()).isEqualTo("coverage");
 
     // values sorted by date
-    assertThat(timeMachine.getCells().length, is(3)); // 3 days
-    assertThat(timeMachine.getCells()[0].getDate().getDate(), is(19));
-    assertThat(timeMachine.getCells()[1].getDate().getDate(), is(21));
-    assertThat(timeMachine.getCells()[2].getDate().getDate(), is(25));
+    assertThat(timeMachine.getCells().length).isEqualTo(3); // 3 days
+    assertThat(getDayOfMonth(timeMachine.getCells()[0].getDate())).isEqualTo(19);
+    assertThat(getDayOfMonth(timeMachine.getCells()[1].getDate())).isEqualTo(21);
+    assertThat(getDayOfMonth(timeMachine.getCells()[2].getDate())).isEqualTo(25);
 
-    assertThat(timeMachine.getCells()[0].getValues().length, is(2));
-    assertThat((Double) timeMachine.getCells()[0].getValues()[0], is(21.0));
-    assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
+    assertThat(timeMachine.getCells()[0].getValues()).hasSize(2);
+    assertThat((Double) timeMachine.getCells()[0].getValues()[0]).isEqualTo(21.0);
+    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
   }
 
   @Test
-  public void shouldAcceptNullValues() throws Exception {
+  public void should_accept_null_values() throws Exception {
     TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/null-values.json"));
 
-    assertThat(timeMachine.getCells()[0].getValues().length, is(2));
-    assertThat(timeMachine.getCells()[0].getValues()[0], nullValue());
-    assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
+    assertThat(timeMachine.getCells()[0].getValues().length).isEqualTo(2);
+    assertThat(timeMachine.getCells()[0].getValues()[0]).isNull();
+    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
 
-    assertThat((Double) timeMachine.getCells()[1].getValues()[0], is(29.0));
-    assertThat(timeMachine.getCells()[1].getValues()[1], nullValue());
+    assertThat((Double) timeMachine.getCells()[1].getValues()[0]).isEqualTo(29.0);
+    assertThat(timeMachine.getCells()[1].getValues()[1]).isNull();
   }
 
   @Test
-  public void shouldCastValues() throws Exception {
+  public void should_cast_values() throws Exception {
     TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/typed-values.json"));
 
-    assertThat(timeMachine.getCells()[0].getValues().length, is(2));
-    assertThat((String) timeMachine.getCells()[0].getValues()[0], is("Sonar way"));
-    assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
+    assertThat(timeMachine.getCells()[0].getValues().length).isEqualTo(2);
+    assertThat((String) timeMachine.getCells()[0].getValues()[0]).isEqualTo("Sonar way");
+    assertThat((Double) timeMachine.getCells()[0].getValues()[1]).isEqualTo(80.0);
+  }
+
+  private int getDayOfMonth(Date date) {
+    Calendar calendar = Calendar.getInstance();
+    calendar.setTime(date);
+    return calendar.get(Calendar.DAY_OF_MONTH);
   }
 }