Refactored MonthComparator into FiscalYearCalculator.
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDateGetCalendarYearTest.java
blobd02c46283b40be3b9212bf095158df802a5df2c8
1 /*
2 * This program is free software. It comes without any warranty, to
3 * the extent permitted by applicable law. You can redistribute it
4 * and/or modify it under the terms of the Do What The Fuck You Want
5 * To Public License, Version 2, as published by Sam Hocevar. See
6 * http://www.wtfpl.net/ for more details.
7 */
8 package com.github.sebhoss.time;
10 import org.joda.time.LocalDate;
11 import org.joda.time.Months;
12 import org.junit.Assert;
13 import org.junit.experimental.theories.DataPoints;
14 import org.junit.experimental.theories.Theories;
15 import org.junit.experimental.theories.Theory;
16 import org.junit.runner.RunWith;
18 import com.github.sebhoss.common.annotation.CompilerWarnings;
20 /**
21 * Test cases for {@link FiscalDate#getCalendarYear()}.
23 @RunWith(Theories.class)
24 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
25 public class FiscalDateGetCalendarYearTest {
27 /** @see TestObjects#supportedMonths() */
28 @DataPoints
29 public static Months[] START_DATES = TestObjects.supportedMonths();
31 /** @see TestObjects#startDates() */
32 @DataPoints
33 public static LocalDate[] MONTH_START_DATES = TestObjects.startDates();
35 /** @see TestObjects#middleDates() */
36 @DataPoints
37 public static LocalDate[] MONTH_MIDDLE_DATES = TestObjects.middleDates();
39 /**
40 * Ensures that for any given date the correct calendar year will be returned in an early fiscal year.
42 * @param startDate
43 * The start date of the fiscal year.
44 * @param currentDate
45 * The current date in a calendar year.
47 @Theory
48 public void shouldReturnCalendarYearInEarlyFiscalYear(final Months startDate, final LocalDate currentDate) {
49 // Given
50 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate).create(currentDate);
52 // When
53 final int calendarYear = fiscalDate.getCalendarYear();
55 // Then
56 Assert.assertEquals(currentDate.getYear(), calendarYear);
59 /**
60 * Ensures that for any given date the correct calendar year will be returned in a late fiscal year.
62 * @param startDate
63 * The start date of the fiscal year.
64 * @param currentDate
65 * The current date in a calendar year.
67 @Theory
68 public void shouldReturnCalendarYearInLateFiscalYear(final Months startDate, final LocalDate currentDate) {
69 // Given
70 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate).create(currentDate);
72 // When
73 final int calendarYear = fiscalDate.getCalendarYear();
75 // Then
76 Assert.assertEquals(currentDate.getYear(), calendarYear);