Last active
August 29, 2015 13:57
-
-
Save Mahoney/9899832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.org.lidalia; | |
import org.joda.time.Interval; | |
import org.joda.time.Period; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import junitparams.JUnitParamsRunner; | |
import junitparams.Parameters; | |
import static com.ft.membership.platform.access.PeriodArithmetic.periodsInAnInterval; | |
import static junitparams.JUnitParamsRunner.$; | |
import static org.hamcrest.Matchers.is; | |
import static org.junit.Assert.assertThat; | |
@RunWith(JUnitParamsRunner.class) | |
public class PeriodArithmeticTest { | |
private Object[] periodsInAnIntervalExpectations() { | |
return $( | |
$(new Interval("2014-03-15/2014-04-16"), new Period("P-1M"), 0), | |
$(new Interval("2014-02-15/2014-03-16"), new Period("P1M"), 1), | |
$(new Interval("2013-12-15/2014-03-16"), new Period("P1M"), 3), | |
$(new Interval("2014-03-15/2014-04-15"), new Period("P1M"), 1), | |
$(new Interval("2014-03-15/2014-04-16"), new Period("P1M"), 1), | |
$(new Interval("2014-01-15/2014-04-16"), new Period("P1M"), 3), | |
$(new Interval("2014-03-15/2014-04-14"), new Period("P1M"), 0), | |
$(new Interval("2014-03-15/3014-04-14"), new Period("P1M"), 12000), | |
$(new Interval("2014-03-15/2014-03-16"), new Period("P10M"), 0) | |
); | |
} | |
@Test @Parameters(method = "periodsInAnIntervalExpectations") | |
public void correctNumberOfPeriodsInAnInterval(Interval interval, Period period, long expectedNumberOfPeriods) { | |
assertThat(periodsInAnInterval(interval, period), is(expectedNumberOfPeriods)); | |
} | |
@Test(expected = ArithmeticException.class) | |
public void cannotDivideByZero() { | |
periodsInAnInterval( | |
new Interval("2014-03-15/2014-04-16"), | |
new Period("P0M")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment