Skip to content

Commit

Permalink
Migrate tests to assertj
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Nov 28, 2017
1 parent 9cf622f commit c0ec2ec
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 493 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>[1.3,)</version>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>
</project>
112 changes: 0 additions & 112 deletions src/test/java/org/shredzone/commons/suncalc/DateMatcher.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
*/
package org.shredzone.commons.suncalc;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.shredzone.commons.suncalc.Locations.COLOGNE_TZ;

import org.assertj.core.data.Offset;
import org.junit.Test;

/**
* Unit tests for {@link MoonIllumination}.
*/
public class MoonIlluminationTest {

private static final double ERROR = 0.1;
private static final Offset<Double> ERROR = Offset.offset(0.1);

@Test
public void testNewMoon() {
MoonIllumination mi = MoonIllumination.compute()
.on(2017, 6, 24, 4, 30, 0)
.timezone(COLOGNE_TZ)
.execute();
assertThat("fraction", mi.getFraction(), is(closeTo(0.0, ERROR)));
assertThat("phase", mi.getPhase(), is(closeTo(175.9, ERROR))); // -180.0
assertThat("angle", mi.getAngle(), is(closeTo(2.0, ERROR)));
assertThat(mi.getFraction()).as("fraction").isCloseTo(0.0, ERROR);
assertThat(mi.getPhase()).as("phase").isCloseTo(175.9, ERROR); // -180.0
assertThat(mi.getAngle()).as("angle").isCloseTo(2.0, ERROR);
}

@Test
Expand All @@ -43,9 +43,9 @@ public void testWaxingHalfMoon() {
.on(2017, 7, 1, 2, 51, 0)
.timezone(COLOGNE_TZ)
.execute();
assertThat("fraction", mi.getFraction(), is(closeTo(0.5, ERROR)));
assertThat("phase", mi.getPhase(), is(closeTo(-89.9, ERROR))); // -90.0
assertThat("angle", mi.getAngle(), is(closeTo(-66.9, ERROR)));
assertThat(mi.getFraction()).as("fraction").isCloseTo(0.5, ERROR);
assertThat(mi.getPhase()).as("phase").isCloseTo(-89.9, ERROR); // -90.0
assertThat(mi.getAngle()).as("angle").isCloseTo(-66.9, ERROR);
}

@Test
Expand All @@ -54,9 +54,9 @@ public void testFullMoon() {
.on(2017, 7, 9, 6, 6, 0)
.timezone(COLOGNE_TZ)
.execute();
assertThat("fraction", mi.getFraction(), is(closeTo(1.0, ERROR)));
assertThat("phase", mi.getPhase(), is(closeTo(-3.1, ERROR))); // 0.0
assertThat("angle", mi.getAngle(), is(closeTo(-7.4, ERROR)));
assertThat(mi.getFraction()).as("fraction").isCloseTo(1.0, ERROR);
assertThat(mi.getPhase()).as("phase").isCloseTo(-3.1, ERROR); // 0.0
assertThat(mi.getAngle()).as("angle").isCloseTo(-7.4, ERROR);
}

@Test
Expand All @@ -65,9 +65,9 @@ public void testWaningHalfMoon() {
.on(2017, 7, 16, 21, 25, 0)
.timezone(COLOGNE_TZ)
.execute();
assertThat("fraction", mi.getFraction(), is(closeTo(0.5, ERROR)));
assertThat("phase", mi.getPhase(), is(closeTo(89.8, ERROR))); // 90.0
assertThat("angle", mi.getAngle(), is(closeTo(68.7, ERROR)));
assertThat(mi.getFraction()).as("fraction").isCloseTo(0.5, ERROR);
assertThat(mi.getPhase()).as("phase").isCloseTo(89.8, ERROR); // 90.0
assertThat(mi.getAngle()).as("angle").isCloseTo(68.7, ERROR);
}

}
56 changes: 28 additions & 28 deletions src/test/java/org/shredzone/commons/suncalc/MoonPositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
*/
package org.shredzone.commons.suncalc;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.shredzone.commons.suncalc.Locations.*;

import org.assertj.core.data.Offset;
import org.junit.Test;

/**
* Unit tests for {@link MoonPosition}.
*/
public class MoonPositionTest {

private static final double ERROR = 0.1;
private static final Offset<Double> ERROR = Offset.offset(0.1);

@Test
public void testCologne() {
Expand All @@ -33,17 +33,17 @@ public void testCologne() {
.at(COLOGNE)
.timezone(COLOGNE_TZ)
.execute();
assertThat("azimuth", mp1.getAzimuth(), is(closeTo(304.8, ERROR)));
assertThat("altitude", mp1.getAltitude(), is(closeTo(-39.6, ERROR)));
assertThat(mp1.getAzimuth()).as("azimuth").isCloseTo(304.8, ERROR);
assertThat(mp1.getAltitude()).as("altitude").isCloseTo(-39.6, ERROR);

MoonPosition mp2 = MoonPosition.compute()
.on(2017, 7, 12, 3, 51, 0)
.at(COLOGNE)
.timezone(COLOGNE_TZ)
.execute();
assertThat("azimuth", mp2.getAzimuth(), is(closeTo(179.9, ERROR)));
assertThat("altitude", mp2.getAltitude(), is(closeTo(25.3, ERROR)));
assertThat("distance", mp2.getDistance(), is(closeTo(391626.1, ERROR)));
assertThat(mp2.getAzimuth()).as("azimuth").isCloseTo(179.9, ERROR);
assertThat(mp2.getAltitude()).as("altitude").isCloseTo(25.3, ERROR);
assertThat(mp2.getDistance()).as("distance").isCloseTo(391626.1, ERROR);
}

@Test
Expand All @@ -53,17 +53,17 @@ public void testAlert() {
.at(ALERT)
.timezone(ALERT_TZ)
.execute();
assertThat("azimuth", mp1.getAzimuth(), is(closeTo(257.5, ERROR)));
assertThat("altitude", mp1.getAltitude(), is(closeTo(-10.9, ERROR)));
assertThat(mp1.getAzimuth()).as("azimuth").isCloseTo(257.5, ERROR);
assertThat(mp1.getAltitude()).as("altitude").isCloseTo(-10.9, ERROR);

MoonPosition mp2 = MoonPosition.compute()
.on(2017, 7, 12, 2, 37, 0)
.at(ALERT)
.timezone(ALERT_TZ)
.execute();
assertThat("azimuth", mp2.getAzimuth(), is(closeTo(179.8, ERROR)));
assertThat("altitude", mp2.getAltitude(), is(closeTo(-5.7, ERROR)));
assertThat("distance", mp2.getDistance(), is(closeTo(390721.7, ERROR)));
assertThat(mp2.getAzimuth()).as("azimuth").isCloseTo(179.8, ERROR);
assertThat(mp2.getAltitude()).as("altitude").isCloseTo(-5.7, ERROR);
assertThat(mp2.getDistance()).as("distance").isCloseTo(390721.7, ERROR);
}

@Test
Expand All @@ -73,17 +73,17 @@ public void testWellington() {
.at(WELLINGTON)
.timezone(WELLINGTON_TZ)
.execute();
assertThat("azimuth", mp1.getAzimuth(), is(closeTo(311.3, ERROR)));
assertThat("altitude", mp1.getAltitude(), is(closeTo(55.1, ERROR)));
assertThat(mp1.getAzimuth()).as("azimuth").isCloseTo(311.3, ERROR);
assertThat(mp1.getAltitude()).as("altitude").isCloseTo(55.1, ERROR);

MoonPosition mp2 = MoonPosition.compute()
.on(2017, 7, 12, 2, 17, 0)
.at(WELLINGTON)
.timezone(WELLINGTON_TZ)
.execute();
assertThat("azimuth", mp2.getAzimuth(), is(closeTo(0.5, ERROR)));
assertThat("altitude", mp2.getAltitude(), is(closeTo(63.9, ERROR)));
assertThat("distance", mp2.getDistance(), is(closeTo(393760.7, ERROR)));
assertThat(mp2.getAzimuth()).as("azimuth").isCloseTo(0.5, ERROR);
assertThat(mp2.getAltitude()).as("altitude").isCloseTo(63.9, ERROR);
assertThat(mp2.getDistance()).as("distance").isCloseTo(393760.7, ERROR);
}

@Test
Expand All @@ -93,17 +93,17 @@ public void testPuertoWilliams() {
.at(PUERTO_WILLIAMS)
.timezone(PUERTO_WILLIAMS_TZ)
.execute();
assertThat("azimuth", mp1.getAzimuth(), is(closeTo(199.4, ERROR)));
assertThat("altitude", mp1.getAltitude(), is(closeTo(-52.7, ERROR)));
assertThat(mp1.getAzimuth()).as("azimuth").isCloseTo(199.4, ERROR);
assertThat(mp1.getAltitude()).as("altitude").isCloseTo(-52.7, ERROR);

MoonPosition mp2 = MoonPosition.compute()
.on(2017, 2, 7, 23, 4, 0)
.at(PUERTO_WILLIAMS)
.timezone(PUERTO_WILLIAMS_TZ)
.execute();
assertThat("azimuth", mp2.getAzimuth(), is(closeTo(0.1, ERROR)));
assertThat("altitude", mp2.getAltitude(), is(closeTo(16.3, ERROR)));
assertThat("distance", mp2.getDistance(), is(closeTo(368900.3, ERROR)));
assertThat(mp2.getAzimuth()).as("azimuth").isCloseTo(0.1, ERROR);
assertThat(mp2.getAltitude()).as("altitude").isCloseTo(16.3, ERROR);
assertThat(mp2.getDistance()).as("distance").isCloseTo(368900.3, ERROR);
}

@Test
Expand All @@ -113,17 +113,17 @@ public void testSingapore() {
.at(SINGAPORE)
.timezone(SINGAPORE_TZ)
.execute();
assertThat("azimuth", mp1.getAzimuth(), is(closeTo(240.6, ERROR)));
assertThat("altitude", mp1.getAltitude(), is(closeTo(57.1, ERROR)));
assertThat(mp1.getAzimuth()).as("azimuth").isCloseTo(240.6, ERROR);
assertThat(mp1.getAltitude()).as("altitude").isCloseTo(57.1, ERROR);

MoonPosition mp2 = MoonPosition.compute()
.on(2017, 7, 12, 3, 11, 0)
.at(SINGAPORE)
.timezone(SINGAPORE_TZ)
.execute();
assertThat("azimuth", mp2.getAzimuth(), is(closeTo(180.0, ERROR)));
assertThat("altitude", mp2.getAltitude(), is(closeTo(74.1, ERROR)));
assertThat("distance", mp2.getDistance(), is(closeTo(392867.9, ERROR)));
assertThat(mp2.getAzimuth()).as("azimuth").isCloseTo(180.0, ERROR);
assertThat(mp2.getAltitude()).as("altitude").isCloseTo(74.1, ERROR);
assertThat(mp2.getDistance()).as("distance").isCloseTo(392867.9, ERROR);
}

}
Loading

0 comments on commit c0ec2ec

Please sign in to comment.