/** * Obtains an instance backed by a period of days. * <p> * If the number of days is an exact multiple of 7 it will be converted to weeks. * * @param days the number of days * @return the tenor * @throws IllegalArgumentException if days is negative or zero */ public static Tenor ofDays(int days) { if (days % 7 == 0) { return ofWeeks(days / 7); } return new Tenor(Period.ofDays(days), days + "D"); }
public void test_of_int() { assertEquals(Tenor.ofDays(1), TENOR_1D); assertEquals(Tenor.ofDays(7), TENOR_1W); assertEquals(Tenor.ofWeeks(2), TENOR_2W); assertEquals(Tenor.ofMonths(1), TENOR_1M); assertEquals(Tenor.ofMonths(15), TENOR_15M); assertEquals(Tenor.ofMonths(18), TENOR_18M); assertEquals(Tenor.ofMonths(21), TENOR_21M); assertEquals(Tenor.ofYears(1), TENOR_1Y); assertEquals(Tenor.ofYears(35), TENOR_35Y); assertEquals(Tenor.ofYears(40), TENOR_40Y); assertEquals(Tenor.ofYears(45), TENOR_45Y); assertEquals(Tenor.ofYears(50), TENOR_50Y); }
@DataProvider(name = "based") public static Object[][] data_based() { return new Object[][] { {Tenor.ofDays(1), false, false}, {Tenor.ofDays(2), false, false}, {Tenor.ofDays(6), false, false}, {Tenor.ofDays(7), true, false}, {Tenor.ofWeeks(1), true, false}, {Tenor.ofWeeks(3), true, false}, {Tenor.ofMonths(1), false, true}, {Tenor.ofMonths(3), false, true}, {Tenor.ofYears(1), false, true}, {Tenor.ofYears(3), false, true}, {Tenor.of(Period.of(1, 2, 3)), false, false}, }; }
public void test_compare() { List<Tenor> tenors = ImmutableList.of( Tenor.ofDays(1), Tenor.ofDays(3), Tenor.ofDays(7), Tenor.ofWeeks(2), Tenor.ofWeeks(4), Tenor.ofDays(30), Tenor.ofMonths(1), Tenor.ofDays(31), Tenor.of(Period.of(0, 1, 1)), Tenor.ofDays(60), Tenor.ofMonths(2), Tenor.ofDays(61), Tenor.ofDays(91), Tenor.ofMonths(3), Tenor.ofDays(92), Tenor.ofDays(182), Tenor.ofMonths(6), Tenor.ofDays(183), Tenor.ofDays(365), Tenor.ofYears(1), Tenor.ofDays(366)); List<Tenor> test = new ArrayList<>(tenors); Collections.shuffle(test); Collections.sort(test); assertEquals(test, tenors); }
public void test_of_notZero() { assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(0))); assertThrowsIllegalArg(() -> Tenor.ofDays(0)); assertThrowsIllegalArg(() -> Tenor.ofWeeks(0)); assertThrowsIllegalArg(() -> Tenor.ofMonths(0)); assertThrowsIllegalArg(() -> Tenor.ofYears(0)); }
public void test_of_notNegative() { assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(-1))); assertThrowsIllegalArg(() -> Tenor.ofDays(-1)); assertThrowsIllegalArg(() -> Tenor.ofWeeks(-1)); assertThrowsIllegalArg(() -> Tenor.ofMonths(-1)); assertThrowsIllegalArg(() -> Tenor.ofYears(-1)); }