fix headers
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDateGetFiscalYearTest.java
bloba47ccc452cdd58cf8d2c3af2a7ad5e6d9ee82776
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 package com.github.sebhoss.time;
9 import java.time.LocalDate;
10 import java.time.Month;
12 import com.github.sebhoss.warnings.CompilerWarnings;
14 import org.junit.Assert;
15 import org.junit.Assume;
16 import org.junit.experimental.theories.DataPoints;
17 import org.junit.experimental.theories.Theories;
18 import org.junit.experimental.theories.Theory;
19 import org.junit.runner.RunWith;
21 /**
22 * Test cases for {@link FiscalDate#getFiscalYear()}.
24 @RunWith(Theories.class)
25 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
26 public class FiscalDateGetFiscalYearTest {
28 /** @see TestObjects#supportedMonths() */
29 @DataPoints
30 public static final Month[] START_DATES = TestObjects.supportedMonths();
32 /** @see TestObjects#startDates() */
33 @DataPoints
34 public static final LocalDate[] MONTH_START_DATES = TestObjects.startDates();
36 /** @see TestObjects#middleDates() */
37 @DataPoints
38 public static final LocalDate[] MONTH_MIDDLE_DATES = TestObjects.middleDates();
40 /**
41 * Ensures that for any given date the fiscal year will be increased if the current calendar date is after the
42 * fiscal year start date.
44 * @param startDate
45 * The start date of the fiscal year.
46 * @param currentDate
47 * The current date in a calendar year.
49 @Theory
50 public void shouldAddYearWhenCurrentDateIsAfterStartDate(final Month startDate, final LocalDate currentDate) {
51 // Given
52 Assume.assumeTrue(currentDate.getMonthValue() >= startDate.getValue());
53 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getValue()).createFromCalendarDate(
54 currentDate);
56 // When
57 final long fiscalYear = fiscalDate.getFiscalYear();
59 // Then
60 Assert.assertEquals(currentDate.getYear() + 1, fiscalYear);
63 /**
64 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is before the
65 * fiscal year start date.
67 * @param startDate
68 * The start date of the fiscal year.
69 * @param currentDate
70 * The current date in a calendar year.
72 @Theory
73 public void shouldNotAddYearWhenCurrentDateIsBeforeStartDate(final Month startDate, final LocalDate currentDate) {
74 // Given
75 Assume.assumeTrue(currentDate.getMonthValue() < startDate.getValue());
76 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getValue()).createFromCalendarDate(
77 currentDate);
79 // When
80 final long fiscalYear = fiscalDate.getFiscalYear();
82 // Then
83 Assert.assertEquals(currentDate.getYear(), fiscalYear);
86 /**
87 * Ensures that for any given date the fiscal year will not be increased if the current calendar date is after the
88 * fiscal year start date.
90 * @param startDate
91 * The start date of the fiscal year.
92 * @param currentDate
93 * The current date in a calendar year.
95 @Theory
96 public void shouldNotAddYearWhenCurrentDateIsAfterStartDate(final Month startDate, final LocalDate currentDate) {
97 // Given
98 Assume.assumeTrue(currentDate.getMonthValue() >= startDate.getValue());
99 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getValue()).createFromCalendarDate(
100 currentDate);
102 // When
103 final long fiscalYear = fiscalDate.getFiscalYear();
105 // Then
106 Assert.assertEquals(currentDate.getYear(), fiscalYear);
110 * Ensures that for any given date the fiscal year will be decreased if the current calendar date is before the
111 * fiscal year start date.
113 * @param startDate
114 * The start date of the fiscal year.
115 * @param currentDate
116 * The current date in a calendar year.
118 @Theory
119 public void shouldSubtractYearWhenCurrentDateIsBeforeStartDate(final Month startDate, final LocalDate currentDate) {
120 // Given
121 Assume.assumeTrue(currentDate.getMonthValue() < startDate.getValue());
122 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getValue()).createFromCalendarDate(
123 currentDate);
125 // When
126 final long fiscalYear = fiscalDate.getFiscalYear();
128 // Then
129 Assert.assertEquals(currentDate.getYear() - 1, fiscalYear);