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 java
.time
.LocalDate
;
17 import java
.time
.Month
;
18 import java
.time
.Period
;
19 import java
.util
.Random
;
21 import com
.github
.sebhoss
.warnings
.CompilerWarnings
;
23 import org
.junit
.Assert
;
24 import org
.junit
.experimental
.theories
.DataPoints
;
25 import org
.junit
.experimental
.theories
.Theories
;
26 import org
.junit
.experimental
.theories
.Theory
;
27 import org
.junit
.runner
.RunWith
;
30 * Test cases for {@link FiscalDate#plusMonths(long)}.
32 @RunWith(Theories
.class)
33 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
34 public class FiscalDatePlusMonthsTest
{
36 /** @see TestObjects#supportedMonths() */
38 public static final Month
[] START_DATES
= TestObjects
.supportedMonths();
40 /** @see TestObjects#startDates() */
42 public static final LocalDate
[] MONTH_START_DATES
= TestObjects
.startDates();
44 /** @see TestObjects#middleDates() */
46 public static final LocalDate
[] MONTH_MIDDLE_DATES
= TestObjects
.middleDates();
48 /** The amount of months to add a given date */
50 public static final int[] ADDITIONAL_MONTHS
= { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 100, 5000 };
52 private static final Random RANDOM
= new Random();
54 /** The amount of random months to add a given date */
56 public static final int[] RANDOM_MONTHS
= RANDOM
.ints(100, -292275054, 292278993).toArray();
59 * Ensures that for any given date a number of years can be added in an early fiscal year.
62 * The start date of the fiscal year.
64 * The current date in a calendar year.
65 * @param additionalMonths
66 * The amounts of months to add.
69 public void shouldAddMonthsInEarlyFiscalYear(final Month startDate
, final LocalDate currentDate
,
70 final int additionalMonths
) {
72 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getValue()).createFromCalendarDate(
76 final FiscalDate newDate
= fiscalDate
.plusMonths(additionalMonths
);
81 Period
.between(FiscalDatePlusMonthsTest
.toLocalDate(fiscalDate
),
82 FiscalDatePlusMonthsTest
.toLocalDate(newDate
)).toTotalMonths());
86 * Ensures that for any given date a number of years can be added in an early fiscal year.
89 * The start date of the fiscal year.
91 * The current date in a calendar year.
92 * @param additionalMonths
93 * The amounts of months to add.
96 public void shouldAddMonthsInLateFiscalYear(final Month startDate
, final LocalDate currentDate
,
97 final int additionalMonths
) {
99 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getValue()).createFromCalendarDate(
103 final FiscalDate newDate
= fiscalDate
.plusMonths(additionalMonths
);
108 Period
.between(FiscalDatePlusMonthsTest
.toLocalDate(fiscalDate
),
109 FiscalDatePlusMonthsTest
.toLocalDate(newDate
)).toTotalMonths());
112 private static LocalDate
toLocalDate(final FiscalDate fiscalDate
) {
113 return LocalDate
.of((int) fiscalDate
.getCalendarYear(), (int) fiscalDate
.getCalendarMonth(),
114 (int) fiscalDate
.getCalendarDayOfMonth());