add missing tests
[fiscal-year.java.git] / src / test / java / com / github / sebhoss / time / FiscalDatePlusWeeksTest.java
blobcb06ad1d40a760e0a3660924561958cf82b82537
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 FiscalDatePlusWeeksTest {
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 weeks to add a given date */
41 @DataPoints
42 public static final int[] ADDITIONAL_WEEKS = { 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 weeks to add a given date */
47 @DataPoints
48 public static final int[] RANDOM_WEEKS = RANDOM.ints(100, -292275054, 292278993).toArray();
50 /**
51 * Ensures that for any given date a number of weeks can be added 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 additionalWeeks
58 * The amounts of weeks to add.
60 @Theory
61 public void shouldAddWeeksInEarlyFiscalYear(final Month startDate, final LocalDate currentDate,
62 final int additionalWeeks) {
63 // Given
64 final FiscalDate fiscalDate = FiscalYears.earlyFiscalYear(startDate.getValue()).createFromCalendarDate(
65 currentDate);
67 // When
68 final FiscalDate newDate = fiscalDate.plusWeeks(additionalWeeks);
70 // Then
71 Assert.assertEquals(
72 fiscalDate.asLocalDate().plusWeeks(additionalWeeks),
73 newDate.asLocalDate());
76 /**
77 * Ensures that for any given date a number of weeks can be added 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 additionalWeeks
84 * The amounts of weeks to add.
86 @Theory
87 public void shouldAddWeeksInLateFiscalYear(final Month startDate, final LocalDate currentDate,
88 final int additionalWeeks) {
89 // Given
90 final FiscalDate fiscalDate = FiscalYears.lateFiscalYear(startDate.getValue()).createFromCalendarDate(
91 currentDate);
93 // When
94 final FiscalDate newDate = fiscalDate.plusWeeks(additionalWeeks);
96 // Then
97 Assert.assertEquals(
98 fiscalDate.asLocalDate().plusWeeks(additionalWeeks),
99 newDate.asLocalDate());