Use new suppress-warnings package
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDatePlusMonthsTest.java
blob08630f89901d0ae261b6536102046e14b712a3f8
1 /*
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.
6 */
7 /*
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;
27 /**
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() */
35 @DataPoints
36 public static final Months[] START_DATES = TestObjects.supportedMonths();
38 /** @see TestObjects#startDates() */
39 @DataPoints
40 public static final LocalDate[] MONTH_START_DATES = TestObjects.startDates();
42 /** @see TestObjects#middleDates() */
43 @DataPoints
44 public static final LocalDate[] MONTH_MIDDLE_DATES = TestObjects.middleDates();
46 /** The amount of months to add a given date */
47 @DataPoints
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 */
51 @DataPoints
52 public static final int[] RANDOM_MONTHS = Datasets.ints().build();
54 /**
55 * Ensures that for any given date a number of years can be added in an early fiscal year.
57 * @param startDate
58 * The start date of the fiscal year.
59 * @param currentDate
60 * The current date in a calendar year.
61 * @param additionalMonths
62 * The amounts of months to add.
64 @Theory
65 public void shouldAddMonthsInEarlyFiscalYear(final Months startDate, final LocalDate currentDate,
66 final int additionalMonths) {
67 // Given
68 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getMonths()).createFromCalendarDate(
69 currentDate);
71 // When
72 final FiscalDate newDate = fiscalDate.plusMonths(additionalMonths);
74 // Then
75 Assert.assertEquals(
76 additionalMonths,
77 Months.monthsBetween(FiscalDatePlusMonthsTest.toLocalDate(fiscalDate),
78 FiscalDatePlusMonthsTest.toLocalDate(newDate)).getMonths());
81 /**
82 * Ensures that for any given date a number of years can be added in an early fiscal year.
84 * @param startDate
85 * The start date of the fiscal year.
86 * @param currentDate
87 * The current date in a calendar year.
88 * @param additionalMonths
89 * The amounts of months to add.
91 @Theory
92 public void shouldAddMonthsInLateFiscalYear(final Months startDate, final LocalDate currentDate,
93 final int additionalMonths) {
94 // Given
95 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getMonths()).createFromCalendarDate(
96 currentDate);
98 // When
99 final FiscalDate newDate = fiscalDate.plusMonths(additionalMonths);
101 // Then
102 Assert.assertEquals(
103 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());