2 * Copyright © 2013 Sebastian Hoß <mail@shoss.de>
3 * This work is free. You can redistribute it and/or modify it under the
4 * terms of the Do What The Fuck You Want To Public License, Version 2,
5 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
7 package com
.github
.sebhoss
.time
;
9 import java
.time
.LocalDate
;
10 import java
.time
.Month
;
12 import com
.github
.sebhoss
.warnings
.CompilerWarnings
;
14 import org
.junit
.Assert
;
15 import org
.junit
.Assume
;
16 import org
.junit
.experimental
.theories
.DataPoints
;
17 import org
.junit
.experimental
.theories
.Theories
;
18 import org
.junit
.experimental
.theories
.Theory
;
19 import org
.junit
.runner
.RunWith
;
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 final Month
[] START_DATES
= TestObjects
.supportedMonths();
32 /** @see TestObjects#startDates() */
34 public static final LocalDate
[] MONTH_START_DATES
= TestObjects
.startDates();
36 /** @see TestObjects#middleDates() */
38 public static final 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 in an early fiscal year.
45 * The start date of the fiscal year.
47 * The current date in a calendar year.
50 public void shouldSubtractMonthWhenCurrentDateIsAfterStartDateInEarlyFiscalYear(final Month startDate
,
51 final LocalDate currentDate
) {
53 Assume
.assumeTrue(currentDate
.getMonthValue() >= startDate
.getValue());
54 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
).createFromCalendarDate(currentDate
);
57 final long fiscalMonth
= fiscalDate
.getFiscalMonth();
60 Assert
.assertEquals(currentDate
.getMonthValue() - startDate
.getValue() + 1, fiscalMonth
);
64 * Ensures that for any given date the fiscal month will be increased if the current calendar date is before the
65 * fiscal year start date in an early fiscal year.
68 * The start date of the fiscal year.
70 * The current date in a calendar year.
73 public void shouldAddMonthWhenCurrentDateIsBeforeStartDateInEarlyFiscalYear(final Month startDate
,
74 final LocalDate currentDate
) {
76 Assume
.assumeTrue(currentDate
.getMonthValue() < startDate
.getValue());
77 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
).createFromCalendarDate(currentDate
);
78 final int fiscalMonthOffset
= Month
.values().length
- startDate
.getValue() + 1;
81 final long fiscalMonth
= fiscalDate
.getFiscalMonth();
84 Assert
.assertEquals(currentDate
.getMonthValue() + fiscalMonthOffset
, fiscalMonth
);
88 * Ensures that for any given date the fiscal month will be decreased if the current calendar date is after the
89 * fiscal year start date in a late fiscal year.
92 * The start date of the fiscal year.
94 * The current date in a calendar year.
97 public void shouldSubtractMonthWhenCurrentDateIsAfterStartDateInLateFiscalYear(final Month startDate
,
98 final LocalDate currentDate
) {
100 Assume
.assumeTrue(currentDate
.getMonthValue() >= startDate
.getValue());
101 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
).createFromCalendarDate(currentDate
);
104 final long fiscalMonth
= fiscalDate
.getFiscalMonth();
107 Assert
.assertEquals(currentDate
.getMonthValue() - startDate
.getValue() + 1, fiscalMonth
);
111 * Ensures that for any given date the fiscal month will be increased if the current calendar date is before the
112 * fiscal year start date in a late fiscal year.
115 * The start date of the fiscal year.
117 * The current date in a calendar year.
120 public void shouldAddMonthWhenCurrentDateIsBeforeStartDateInLateFiscalYear(final Month startDate
,
121 final LocalDate currentDate
) {
123 Assume
.assumeTrue(currentDate
.getMonthValue() < startDate
.getValue());
124 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
).createFromCalendarDate(currentDate
);
125 final int fiscalMonthOffset
= Month
.values().length
- startDate
.getValue() + 1;
128 final long fiscalMonth
= fiscalDate
.getFiscalMonth();
131 Assert
.assertEquals(currentDate
.getMonthValue() + fiscalMonthOffset
, fiscalMonth
);