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#getFiscalYear()}.
24 @RunWith(Theories
.class)
25 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
26 public class FiscalDateGetFiscalYearTest
{
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 year will be increased 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 shouldAddYearWhenCurrentDateIsAfterStartDate(final Month startDate
, final LocalDate currentDate
) {
52 Assume
.assumeTrue(currentDate
.getMonthValue() >= startDate
.getValue());
53 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getValue()).createFromCalendarDate(
57 final long fiscalYear
= fiscalDate
.getFiscalYear();
60 Assert
.assertEquals(currentDate
.getYear() + 1, fiscalYear
);
64 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is before the
65 * fiscal year start date.
68 * The start date of the fiscal year.
70 * The current date in a calendar year.
73 public void shouldNotAddYearWhenCurrentDateIsBeforeStartDate(final Month startDate
, final LocalDate currentDate
) {
75 Assume
.assumeTrue(currentDate
.getMonthValue() < startDate
.getValue());
76 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getValue()).createFromCalendarDate(
80 final long fiscalYear
= fiscalDate
.getFiscalYear();
83 Assert
.assertEquals(currentDate
.getYear(), fiscalYear
);
87 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is after the
88 * fiscal year start date.
91 * The start date of the fiscal year.
93 * The current date in a calendar year.
96 public void shouldNotAddYearWhenCurrentDateIsAfterStartDate(final Month startDate
, final LocalDate currentDate
) {
98 Assume
.assumeTrue(currentDate
.getMonthValue() >= startDate
.getValue());
99 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getValue()).createFromCalendarDate(
103 final long fiscalYear
= fiscalDate
.getFiscalYear();
106 Assert
.assertEquals(currentDate
.getYear(), fiscalYear
);
110 * Ensures that for any given date the fiscal year will be decreased if the current calendar date is before the
111 * fiscal year start date.
114 * The start date of the fiscal year.
116 * The current date in a calendar year.
119 public void shouldSubtractYearWhenCurrentDateIsBeforeStartDate(final Month startDate
, final LocalDate currentDate
) {
121 Assume
.assumeTrue(currentDate
.getMonthValue() < startDate
.getValue());
122 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getValue()).createFromCalendarDate(
126 final long fiscalYear
= fiscalDate
.getFiscalYear();
129 Assert
.assertEquals(currentDate
.getYear() - 1, fiscalYear
);