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.
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
;
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() */
30 public static final Month
[] START_DATES
= TestObjects
.supportedMonths();
32 /** @see TestObjects#startDates() */
34 public static final LocalDate
[] MONTH_START_DATES
= TestObjects
.startDates();
36 /** @see TestObjects#middleDates() */
38 public static final LocalDate
[] MONTH_MIDDLE_DATES
= TestObjects
.middleDates();
40 /** The amount of weeks to add a given date */
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 */
48 public static final int[] RANDOM_WEEKS
= RANDOM
.ints(100, -292275054, 292278993).toArray();
51 * Ensures that for any given date a number of weeks can be added in an early fiscal year.
54 * The start date of the fiscal year.
56 * The current date in a calendar year.
57 * @param additionalWeeks
58 * The amounts of weeks to add.
61 public void shouldAddWeeksInEarlyFiscalYear(final Month startDate
, final LocalDate currentDate
,
62 final int additionalWeeks
) {
64 final FiscalDate fiscalDate
= FiscalYears
.earlyFiscalYear(startDate
.getValue()).createFromCalendarDate(
68 final FiscalDate newDate
= fiscalDate
.plusWeeks(additionalWeeks
);
72 fiscalDate
.asLocalDate().plusWeeks(additionalWeeks
),
73 newDate
.asLocalDate());
77 * Ensures that for any given date a number of weeks can be added in a late fiscal year.
80 * The start date of the fiscal year.
82 * The current date in a calendar year.
83 * @param additionalWeeks
84 * The amounts of weeks to add.
87 public void shouldAddWeeksInLateFiscalYear(final Month startDate
, final LocalDate currentDate
,
88 final int additionalWeeks
) {
90 final FiscalDate fiscalDate
= FiscalYears
.lateFiscalYear(startDate
.getValue()).createFromCalendarDate(
94 final FiscalDate newDate
= fiscalDate
.plusWeeks(additionalWeeks
);
98 fiscalDate
.asLocalDate().plusWeeks(additionalWeeks
),
99 newDate
.asLocalDate());