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
.datasets
.Datasets
;
17 import com
.github
.sebhoss
.warnings
.CompilerWarnings
;
19 import org
.joda
.time
.LocalDate
;
20 import org
.joda
.time
.Months
;
21 import org
.junit
.Assert
;
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#plusMonths(int)}.
30 @RunWith(Theories
.class)
31 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
32 public class FiscalDatePlusMonthsTest
{
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();
46 /** The amount of months to add a given date */
48 public static final int[] ADDITIONAL_MONTHS
= { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 100, 5000 };
50 /** The amount of random months to add a given date */
52 public static final int[] RANDOM_MONTHS
= Datasets
.ints().build();
55 * Ensures that for any given date a number of years can be added in an early fiscal year.
58 * The start date of the fiscal year.
60 * The current date in a calendar year.
61 * @param additionalMonths
62 * The amounts of months to add.
65 public void shouldAddMonthsInEarlyFiscalYear(final Months startDate
, final LocalDate currentDate
,
66 final int additionalMonths
) {
68 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getMonths()).createFromCalendarDate(
72 final FiscalDate newDate
= fiscalDate
.plusMonths(additionalMonths
);
77 Months
.monthsBetween(FiscalDatePlusMonthsTest
.toLocalDate(fiscalDate
),
78 FiscalDatePlusMonthsTest
.toLocalDate(newDate
)).getMonths());
82 * Ensures that for any given date a number of years can be added in an early fiscal year.
85 * The start date of the fiscal year.
87 * The current date in a calendar year.
88 * @param additionalMonths
89 * The amounts of months to add.
92 public void shouldAddMonthsInLateFiscalYear(final Months startDate
, final LocalDate currentDate
,
93 final int additionalMonths
) {
95 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getMonths()).createFromCalendarDate(
99 final FiscalDate newDate
= fiscalDate
.plusMonths(additionalMonths
);
104 Months
.monthsBetween(FiscalDatePlusMonthsTest
.toLocalDate(fiscalDate
),
105 FiscalDatePlusMonthsTest
.toLocalDate(newDate
)).getMonths());
108 private static LocalDate
toLocalDate(final FiscalDate fiscalDate
) {
109 return new LocalDate(fiscalDate
.getCalendarYear(), fiscalDate
.getCalendarMonth(),
110 fiscalDate
.getCalendarDayOfMonth());