Use new suppress-warnings package
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDateGetFiscalYearTest.java
blob3384bf2914001f13012bcaf2d49849b3d588e5a6
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.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;
27 /**
28 * Test cases for {@link FiscalDate#getFiscalYear()}.
30 @RunWith(Theories.class)
31 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
32 public class FiscalDateGetFiscalYearTest {
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 /**
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.
50 * @param startDate
51 * The start date of the fiscal year.
52 * @param currentDate
53 * The current date in a calendar year.
55 @Theory
56 public void shouldAddYearWhenCurrentDateIsAfterStartDate(final Months startDate, final LocalDate currentDate) {
57 // Given
58 Assume.assumeTrue(currentDate.getMonthOfYear() >= startDate.getMonths());
59 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getMonths()).createFromCalendarDate(
60 currentDate);
62 // When
63 final int fiscalYear = fiscalDate.getFiscalYear();
65 // Then
66 Assert.assertEquals(currentDate.getYear() + 1, fiscalYear);
69 /**
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.
73 * @param startDate
74 * The start date of the fiscal year.
75 * @param currentDate
76 * The current date in a calendar year.
78 @Theory
79 public void shouldNotAddYearWhenCurrentDateIsBeforeStartDate(final Months startDate, final LocalDate currentDate) {
80 // Given
81 Assume.assumeTrue(currentDate.getMonthOfYear() < startDate.getMonths());
82 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getMonths()).createFromCalendarDate(
83 currentDate);
85 // When
86 final int fiscalYear = fiscalDate.getFiscalYear();
88 // Then
89 Assert.assertEquals(currentDate.getYear(), fiscalYear);
92 /**
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.
96 * @param startDate
97 * The start date of the fiscal year.
98 * @param currentDate
99 * The current date in a calendar year.
101 @Theory
102 public void shouldNotAddYearWhenCurrentDateIsAfterStartDate(final Months startDate, final LocalDate currentDate) {
103 // Given
104 Assume.assumeTrue(currentDate.getMonthOfYear() >= startDate.getMonths());
105 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getMonths()).createFromCalendarDate(
106 currentDate);
108 // When
109 final int fiscalYear = fiscalDate.getFiscalYear();
111 // Then
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.
119 * @param startDate
120 * The start date of the fiscal year.
121 * @param currentDate
122 * The current date in a calendar year.
124 @Theory
125 public void shouldSubtractYearWhenCurrentDateIsBeforeStartDate(final Months startDate, final LocalDate currentDate) {
126 // Given
127 Assume.assumeTrue(currentDate.getMonthOfYear() < startDate.getMonths());
128 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getMonths()).createFromCalendarDate(
129 currentDate);
131 // When
132 final int fiscalYear = fiscalDate.getFiscalYear();
134 // Then
135 Assert.assertEquals(currentDate.getYear() - 1, fiscalYear);