fix headers
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDateGetFiscalMonthTest.java
blob4efb671e91d88f2144cc5b4ef7f3add21c46c1e0
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#getFiscalMonth()}.
24 @RunWith(Theories.class)
25 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
26 public class FiscalDateGetFiscalMonthTest {
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 month will be decreased if the current calendar date is after the
42 * fiscal year start date in an early fiscal year.
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 shouldSubtractMonthWhenCurrentDateIsAfterStartDateInEarlyFiscalYear(final Month startDate,
51 final LocalDate currentDate) {
52 // Given
53 Assume.assumeTrue(currentDate.getMonthValue() >= startDate.getValue());
54 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate).createFromCalendarDate(currentDate);
56 // When
57 final long fiscalMonth = fiscalDate.getFiscalMonth();
59 // Then
60 Assert.assertEquals(currentDate.getMonthValue() - startDate.getValue() + 1, fiscalMonth);
63 /**
64 * Ensures that for any given date the fiscal month will be increased if the current calendar date is before the
65 * fiscal year start date in an early fiscal year.
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 shouldAddMonthWhenCurrentDateIsBeforeStartDateInEarlyFiscalYear(final Month startDate,
74 final LocalDate currentDate) {
75 // Given
76 Assume.assumeTrue(currentDate.getMonthValue() < startDate.getValue());
77 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate).createFromCalendarDate(currentDate);
78 final int fiscalMonthOffset = Month.values().length - startDate.getValue() + 1;
80 // When
81 final long fiscalMonth = fiscalDate.getFiscalMonth();
83 // Then
84 Assert.assertEquals(currentDate.getMonthValue() + fiscalMonthOffset, fiscalMonth);
87 /**
88 * Ensures that for any given date the fiscal month will be decreased if the current calendar date is after the
89 * fiscal year start date in a late fiscal year.
91 * @param startDate
92 * The start date of the fiscal year.
93 * @param currentDate
94 * The current date in a calendar year.
96 @Theory
97 public void shouldSubtractMonthWhenCurrentDateIsAfterStartDateInLateFiscalYear(final Month startDate,
98 final LocalDate currentDate) {
99 // Given
100 Assume.assumeTrue(currentDate.getMonthValue() >= startDate.getValue());
101 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate).createFromCalendarDate(currentDate);
103 // When
104 final long fiscalMonth = fiscalDate.getFiscalMonth();
106 // Then
107 Assert.assertEquals(currentDate.getMonthValue() - startDate.getValue() + 1, fiscalMonth);
111 * Ensures that for any given date the fiscal month will be increased if the current calendar date is before the
112 * fiscal year start date in a late fiscal year.
114 * @param startDate
115 * The start date of the fiscal year.
116 * @param currentDate
117 * The current date in a calendar year.
119 @Theory
120 public void shouldAddMonthWhenCurrentDateIsBeforeStartDateInLateFiscalYear(final Month startDate,
121 final LocalDate currentDate) {
122 // Given
123 Assume.assumeTrue(currentDate.getMonthValue() < startDate.getValue());
124 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate).createFromCalendarDate(currentDate);
125 final int fiscalMonthOffset = Month.values().length - startDate.getValue() + 1;
127 // When
128 final long fiscalMonth = fiscalDate.getFiscalMonth();
130 // Then
131 Assert.assertEquals(currentDate.getMonthValue() + fiscalMonthOffset, fiscalMonth);