2 * This program is free software. It comes without any warranty, to
3 * the extent permitted by applicable law. You can redistribute it
4 * and/or modify it under the terms of the Do What The Fuck You Want
5 * To Public License, Version 2, as published by Sam Hocevar. See
6 * http://www.wtfpl.net/ for more details.
8 package com
.github
.sebhoss
.time
;
10 import org
.joda
.time
.LocalDate
;
11 import org
.joda
.time
.Months
;
12 import org
.junit
.Assert
;
13 import org
.junit
.Assume
;
14 import org
.junit
.experimental
.theories
.DataPoints
;
15 import org
.junit
.experimental
.theories
.Theories
;
16 import org
.junit
.experimental
.theories
.Theory
;
17 import org
.junit
.runner
.RunWith
;
19 import com
.github
.sebhoss
.common
.annotation
.CompilerWarnings
;
22 * Test cases for {@link FiscalDate#getFiscalMonth()}.
24 @RunWith(Theories
.class)
25 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
26 public class FiscalDateGetFiscalMonthTest
{
28 /** @see TestObjects#supportedMonths() */
30 public static Months
[] START_DATES
= TestObjects
.supportedMonths();
32 /** @see TestObjects#startDates() */
34 public static LocalDate
[] MONTH_START_DATES
= TestObjects
.startDates();
36 /** @see TestObjects#middleDates() */
38 public static LocalDate
[] MONTH_MIDDLE_DATES
= TestObjects
.middleDates();
41 * Ensures that for any given date the fiscal month will be decreased if the current calendar date is after the
42 * fiscal year start date.
45 * The start date of the fiscal year.
47 * The current date in a calendar year.
50 public void shouldSubtractMonthWhenCurrentDateIsAfterStartDate(final Months startDate
, final LocalDate currentDate
) {
52 Assume
.assumeTrue(currentDate
.getMonthOfYear() >= startDate
.getMonths());
53 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
).create(currentDate
);
56 final int fiscalMonth
= fiscalDate
.getFiscalMonth();
59 Assert
.assertEquals(currentDate
.getMonthOfYear() - startDate
.getMonths() + 1, fiscalMonth
);
63 * Ensures that for any given date the fiscal month will be increased if the current calendar date is before the
64 * fiscal year start date.
67 * The start date of the fiscal year.
69 * The current date in a calendar year.
72 public void shouldAddMonthWhenCurrentDateIsBeforeStartDate(final Months startDate
, final LocalDate currentDate
) {
74 Assume
.assumeTrue(currentDate
.getMonthOfYear() < startDate
.getMonths());
75 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
).create(currentDate
);
76 final int fiscalMonthOffset
= currentDate
.monthOfYear().getMaximumValue() - startDate
.getMonths() + 1;
79 final int fiscalMonth
= fiscalDate
.getFiscalMonth();
82 Assert
.assertEquals(currentDate
.getMonthOfYear() + fiscalMonthOffset
, fiscalMonth
);