From f7de01e723f1ce7bf390e67d1960287037bfe50d Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 21 Jan 2013 11:26:44 +0100 Subject: [PATCH] Replace Junit / Hamcrest by FestAssert --- .../TimeMachineUnmarshallerTest.java | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java index 6df65a51e61..09561017e2e 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java @@ -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); } } -- 2.39.5