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.
8 * This program is free software. It comes without any warranty, to
9 * the extent permitted by applicable law. You can redistribute it
10 * and/or modify it under the terms of the Do What The Fuck You Want
11 * To Public License, Version 2, as published by Sam Hocevar. See
12 * http://www.wtfpl.net/ for more details.
14 package com
.github
.sebhoss
.time
;
16 import com
.github
.sebhoss
.warnings
.CompilerWarnings
;
18 import org
.joda
.time
.LocalDate
;
19 import org
.joda
.time
.Months
;
20 import org
.junit
.Assert
;
21 import org
.junit
.Assume
;
22 import org
.junit
.experimental
.theories
.DataPoints
;
23 import org
.junit
.experimental
.theories
.Theories
;
24 import org
.junit
.experimental
.theories
.Theory
;
25 import org
.junit
.runner
.RunWith
;
28 * Test cases for {@link FiscalDate#getFiscalYear()}.
30 @RunWith(Theories
.class)
31 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
32 public class FiscalDateGetFiscalYearTest
{
34 /** @see TestObjects#supportedMonths() */
36 public static final Months
[] START_DATES
= TestObjects
.supportedMonths();
38 /** @see TestObjects#startDates() */
40 public static final LocalDate
[] MONTH_START_DATES
= TestObjects
.startDates();
42 /** @see TestObjects#middleDates() */
44 public static final LocalDate
[] MONTH_MIDDLE_DATES
= TestObjects
.middleDates();
47 * Ensures that for any given date the fiscal year will be increased if the current calendar date is after the
48 * fiscal year start date.
51 * The start date of the fiscal year.
53 * The current date in a calendar year.
56 public void shouldAddYearWhenCurrentDateIsAfterStartDate(final Months startDate
, final LocalDate currentDate
) {
58 Assume
.assumeTrue(currentDate
.getMonthOfYear() >= startDate
.getMonths());
59 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getMonths()).createFromCalendarDate(
63 final int fiscalYear
= fiscalDate
.getFiscalYear();
66 Assert
.assertEquals(currentDate
.getYear() + 1, fiscalYear
);
70 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is before the
71 * fiscal year start date.
74 * The start date of the fiscal year.
76 * The current date in a calendar year.
79 public void shouldNotAddYearWhenCurrentDateIsBeforeStartDate(final Months startDate
, final LocalDate currentDate
) {
81 Assume
.assumeTrue(currentDate
.getMonthOfYear() < startDate
.getMonths());
82 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getMonths()).createFromCalendarDate(
86 final int fiscalYear
= fiscalDate
.getFiscalYear();
89 Assert
.assertEquals(currentDate
.getYear(), fiscalYear
);
93 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is after the
94 * fiscal year start date.
97 * The start date of the fiscal year.
99 * The current date in a calendar year.
102 public void shouldNotAddYearWhenCurrentDateIsAfterStartDate(final Months startDate
, final LocalDate currentDate
) {
104 Assume
.assumeTrue(currentDate
.getMonthOfYear() >= startDate
.getMonths());
105 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getMonths()).createFromCalendarDate(
109 final int fiscalYear
= fiscalDate
.getFiscalYear();
112 Assert
.assertEquals(currentDate
.getYear(), fiscalYear
);
116 * Ensures that for any given date the fiscal year will be decreased if the current calendar date is before the
117 * fiscal year start date.
120 * The start date of the fiscal year.
122 * The current date in a calendar year.
125 public void shouldSubtractYearWhenCurrentDateIsBeforeStartDate(final Months startDate
, final LocalDate currentDate
) {
127 Assume
.assumeTrue(currentDate
.getMonthOfYear() < startDate
.getMonths());
128 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getMonths()).createFromCalendarDate(
132 final int fiscalYear
= fiscalDate
.getFiscalYear();
135 Assert
.assertEquals(currentDate
.getYear() - 1, fiscalYear
);