add missing tests
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDateMinusDaysTest.java
blob40ee30ebf1d31fbb60195eb6808d89f0704c02bf
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;
11 import java.util.Random;
13 import com.github.sebhoss.warnings.CompilerWarnings;
15 import org.junit.Assert;
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#plusWeeks(long)}.
24 @RunWith(Theories.class)
25 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
26 public class FiscalDateMinusDaysTest {
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 /** The amount of days to subtract from a given date */
41 @DataPoints
42 public static final int[] ADDITIONAL_DAYS = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 100, 5000 };
44 private static final Random RANDOM = new Random();
46 /** The amount of random days to subtract from a given date */
47 @DataPoints
48 public static final int[] RANDOM_DAYS = RANDOM.ints(100, -292275054, 292278993).toArray();
50 /**
51 * Ensures that for any given date a number of days can be subtracted in an early fiscal year.
53 * @param startDate
54 * The start date of the fiscal year.
55 * @param currentDate
56 * The current date in a calendar year.
57 * @param additionalDays
58 * The amounts of days to subtract.
60 @Theory
61 public void shouldSubtractDaysInEarlyFiscalYear(final Month startDate, final LocalDate currentDate,
62 final int additionalDays) {
63 // Given
64 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getValue()).createFromCalendarDate(
65 currentDate);
67 // When
68 final FiscalDate newDate = fiscalDate.minusDays(additionalDays);
70 // Then
71 Assert.assertEquals(
72 fiscalDate.asLocalDate().minusDays(additionalDays),
73 newDate.asLocalDate());
76 /**
77 * Ensures that for any given date a number of days can be subtracted in a late fiscal year.
79 * @param startDate
80 * The start date of the fiscal year.
81 * @param currentDate
82 * The current date in a calendar year.
83 * @param additionalDays
84 * The amounts of days to subtract.
86 @Theory
87 public void shouldSubtractDaysInLateFiscalYear(final Month startDate, final LocalDate currentDate,
88 final int additionalDays) {
89 // Given
90 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getValue()).createFromCalendarDate(
91 currentDate);
93 // When
94 final FiscalDate newDate = fiscalDate.minusDays(additionalDays);
96 // Then
97 Assert.assertEquals(
98 fiscalDate.asLocalDate().minusDays(additionalDays),
99 newDate.asLocalDate());