@Theory
 public void test_isIn_assertion(ZonedDateTime referenceDate) {
   // WHEN
   assertThat(referenceDate)
       .isIn(referenceDate.toString(), referenceDate.plus(1, ChronoUnit.MILLIS).toString());
   // THEN
   verify_that_isIn_assertion_fails_and_throws_AssertionError(referenceDate);
 }
 private static void verify_that_isNotIn_assertion_fails_and_throws_AssertionError(
     ZonedDateTime reference) {
   try {
     assertThat(reference)
         .isNotIn(reference.toString(), reference.plus(1, ChronoUnit.MILLIS).toString());
   } catch (AssertionError e) {
     // AssertionError was expected
     return;
   }
   fail("Should have thrown AssertionError");
 }
Пример #3
0
  public static void main(String[] args) {
    ZonedDateTime apollo11launch =
        ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));
    // 1969-07-16T09:32-04:00[America/New_York]
    System.out.println("apollo11launch: " + apollo11launch);

    Instant instant = apollo11launch.toInstant();
    System.out.println("instant: " + instant);

    ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC"));
    System.out.println("zonedDateTime: " + zonedDateTime);

    ZonedDateTime skipped =
        ZonedDateTime.of(
            LocalDate.of(2013, 3, 31), LocalTime.of(2, 30), ZoneId.of("Europe/Berlin"));
    // Constructs March 31 3:30
    System.out.println("skipped: " + skipped);

    ZonedDateTime ambiguous =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 27), // End of daylight savings time
            LocalTime.of(2, 30),
            ZoneId.of("Europe/Berlin"));
    // 2013-10-27T02:30+02:00[Europe/Berlin]
    ZonedDateTime anHourLater = ambiguous.plusHours(1);
    // 2013-10-27T02:30+01:00[Europe/Berlin]
    System.out.println("ambiguous: " + ambiguous);
    System.out.println("anHourLater: " + anHourLater);

    ZonedDateTime meeting =
        ZonedDateTime.of(
            LocalDate.of(2013, 10, 31), LocalTime.of(14, 30), ZoneId.of("America/Los_Angeles"));
    System.out.println("meeting: " + meeting);
    ZonedDateTime nextMeeting = meeting.plus(Duration.ofDays(7));
    // Caution! Won’t work with daylight savings time
    System.out.println("nextMeeting: " + nextMeeting);
    nextMeeting = meeting.plus(Period.ofDays(7)); // OK
    System.out.println("nextMeeting: " + nextMeeting);
  }
Пример #4
0
 /**
  * New conditions element.
  *
  * @param issuedAt the issued at
  * @param audienceUri the service id
  * @param issueLength the issue length
  * @return the conditions
  */
 public Conditions newConditions(
     final ZonedDateTime issuedAt, final String audienceUri, final long issueLength) {
   final Conditions conditions = newSamlObject(Conditions.class);
   conditions.setNotBefore(DateTimeUtils.dateTimeOf(issuedAt));
   conditions.setNotOnOrAfter(
       DateTimeUtils.dateTimeOf(issuedAt.plus(issueLength, ChronoUnit.MILLIS)));
   final AudienceRestrictionCondition audienceRestriction =
       newSamlObject(AudienceRestrictionCondition.class);
   final Audience audience = newSamlObject(Audience.class);
   audience.setUri(audienceUri);
   audienceRestriction.getAudiences().add(audience);
   conditions.getAudienceRestrictionConditions().add(audienceRestriction);
   return conditions;
 }
/** Tests related to the construction of CMS cap/floor. */
@Test
public class AnnuityCapFloorCMSDefinitionTest {
  private static final Currency CUR = Currency.EUR;
  private static final HolidayCalendar CALENDAR = HolidayCalendars.SAT_SUN;
  // Ibor index
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventions.MODIFIED_FOLLOWING;
  private static final boolean IS_EOM = true;
  private static final Period IBOR_TENOR = Period.ofMonths(3);
  private static final int IBOR_SETTLEMENT_DAYS = 2;
  private static final DayCount IBOR_DAY_COUNT = DayCounts.ACT_360;
  private static final IborIndex IBOR_INDEX =
      new IborIndex(
          CUR, IBOR_TENOR, IBOR_SETTLEMENT_DAYS, IBOR_DAY_COUNT, BUSINESS_DAY, IS_EOM, "Ibor");
  // CMS 10Y
  private static final Period CMS_TENOR = Period.ofYears(10);
  private static final Period FIXED_PAYMENT_PERIOD = Period.ofMonths(6);
  private static final DayCount FIXED_DAY_COUNT = DayCounts.THIRTY_U_360;
  private static final IndexSwap CMS_INDEX =
      new IndexSwap(FIXED_PAYMENT_PERIOD, FIXED_DAY_COUNT, IBOR_INDEX, CMS_TENOR, CALENDAR);
  // Annuity
  private static final ZonedDateTime START_DATE = DateUtils.getUTCDate(2011, 3, 17);
  private static final Period ANNUITY_TENOR = Period.ofYears(5);
  private static final ZonedDateTime MATURITY_DATE = START_DATE.plus(ANNUITY_TENOR);
  private static final double NOTIONAL = 100000000; // 100m
  private static final Period LEG_PAYMENT_PERIOD = Period.ofMonths(12);
  private static final DayCount LEG_DAY_COUNT = DayCounts.ACT_365F;
  private static final boolean IS_PAYER = true;
  private static final double STRIKE = 0.04;
  private static final boolean IS_CAP = true;
  private static final AnnuityCapFloorCMSDefinition CMS_LEG =
      AnnuityCapFloorCMSDefinition.from(
          START_DATE,
          MATURITY_DATE,
          NOTIONAL,
          CMS_INDEX,
          LEG_PAYMENT_PERIOD,
          LEG_DAY_COUNT,
          IS_PAYER,
          STRIKE,
          IS_CAP,
          CALENDAR);

  @Test
  public void dates() {
    final IborIndex fakeIborIndex12 =
        new IborIndex(
            CUR,
            LEG_PAYMENT_PERIOD,
            IBOR_SETTLEMENT_DAYS,
            LEG_DAY_COUNT,
            BUSINESS_DAY,
            IS_EOM,
            "Ibor");
    final AnnuityCouponIborDefinition iborLeg =
        AnnuityCouponIborDefinition.from(
            START_DATE, MATURITY_DATE, NOTIONAL, fakeIborIndex12, IS_PAYER, CALENDAR);
    for (int loopcpn = 0; loopcpn < iborLeg.getNumberOfPayments(); loopcpn++) {
      assertEquals(
          iborLeg.getNthPayment(loopcpn).getAccrualStartDate(),
          CMS_LEG.getNthPayment(loopcpn).getAccrualStartDate());
      assertEquals(
          iborLeg.getNthPayment(loopcpn).getAccrualEndDate(),
          CMS_LEG.getNthPayment(loopcpn).getAccrualEndDate());
      assertEquals(
          iborLeg.getNthPayment(loopcpn).getPaymentYearFraction(),
          CMS_LEG.getNthPayment(loopcpn).getPaymentYearFraction());
      assertEquals(
          iborLeg.getNthPayment(loopcpn).getPaymentDate(),
          CMS_LEG.getNthPayment(loopcpn).getPaymentDate());
      assertEquals(
          iborLeg.getNthPayment(loopcpn).getFixingDate(),
          CMS_LEG.getNthPayment(loopcpn).getFixingDate());
    }
  }

  @Test
  public void common() {
    for (int loopcpn = 0; loopcpn < CMS_LEG.getNumberOfPayments(); loopcpn++) {
      assertEquals(CMS_INDEX, CMS_LEG.getNthPayment(loopcpn).getCMSIndex());
      assertEquals(
          NOTIONAL * (IS_PAYER ? -1.0 : 1.0), CMS_LEG.getNthPayment(loopcpn).getNotional());
      assertEquals(STRIKE, CMS_LEG.getNthPayment(loopcpn).getStrike());
      assertEquals(IS_CAP, CMS_LEG.getNthPayment(loopcpn).isCap());
    }
    final AnnuityCapFloorCMSDefinition cmsCapReceiver =
        AnnuityCapFloorCMSDefinition.from(
            START_DATE,
            MATURITY_DATE,
            NOTIONAL,
            CMS_INDEX,
            LEG_PAYMENT_PERIOD,
            LEG_DAY_COUNT,
            !IS_PAYER,
            STRIKE,
            IS_CAP,
            CALENDAR);
    for (int loopcpn = 0; loopcpn < CMS_LEG.getNumberOfPayments(); loopcpn++) {
      assertEquals(CMS_INDEX, cmsCapReceiver.getNthPayment(loopcpn).getCMSIndex());
      assertEquals(
          -NOTIONAL * (IS_PAYER ? -1.0 : 1.0), cmsCapReceiver.getNthPayment(loopcpn).getNotional());
    }
  }
}