Example usage for java.time LocalDate parse

List of usage examples for java.time LocalDate parse

Introduction

In this page you can find the example usage for java.time LocalDate parse.

Prototype

public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

Obtains an instance of LocalDate from a text string using a specific formatter.

Usage

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testApplyRulesCallsBookingManagerCorrectly_FutureRecurringRuleNoExclusion() throws Exception {
    // A recurring rule with no exclusion for the apply date, but that does not
    // begin until after the apply date should not cause a booking to be made.

    // ARRANGE/*from  ww  w.  ja v  a 2s. c o m*/
    initialiseRuleManager();
    expectOptimisticPersisterToReturnVersionedAttributes(42);
    expectPurgeExpiredRulesAndRuleExclusions(42, existingBookingRules);
    mockery.checking(new Expectations() {
        {
            never(mockBookingManager).createBooking(with(anything()), with.booleanIs(anything()));
        }
    });

    // Get date before start date of rule
    String initialDate = existingFridayRecurringRuleWithoutExclusions.getBooking().getDate();
    String earlierDate = LocalDate.parse(initialDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(2)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    // ACT
    // This should not create a booking
    ruleManager.applyRules(earlierDate, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testApplyRulesCallsBookingManagerCorrectly_NoRelevantRules() throws Exception {
    // An apply date with no relevant rules should not cause a booking to be
    // made, but should still purge expired rules and exclusions.

    // ARRANGE//from   ww  w .  j a  v a2s.co m
    initialiseRuleManager();
    expectOptimisticPersisterToReturnVersionedAttributes(42);
    expectPurgeExpiredRulesAndRuleExclusions(42, existingBookingRules);
    mockery.checking(new Expectations() {
        {
            never(mockBookingManager).createBooking(with(anything()), with.booleanIs(anything()));
        }
    });

    // Get date for day of week different to any rule's
    String friday = existingFridayRecurringRuleWithoutExclusions.getBooking().getDate();
    String monday = LocalDate.parse(friday, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusDays(3)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    // ACT
    // This should not create a booking - none of our rules are for mondays
    ruleManager.applyRules(monday, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testApplyRulesToleratesApplyDateInThePast() throws Exception {
    // An apply date in the past should not cause a booking to be made, but
    // should still purge expired rules and exclusions.

    // ARRANGE/*from   w w  w .  jav  a2  s. c  o  m*/
    initialiseRuleManager();
    expectPurgeExpiredRulesAndRuleExclusions(42, existingBookingRules);
    mockery.checking(new Expectations() {
        {
            never(mockBookingManager).createBooking(with(anything()), with.booleanIs(anything()));
        }
    });

    // Get date before our current date
    String pastDate = LocalDate.parse(fakeCurrentSaturdayDateString, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
            .minusWeeks(33).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    // ACT
    // This should be tolerated even though the date is in the past
    ruleManager.applyRules(pastDate, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testApplyRulesCallsBookingManagerCorrectly_PurgeExpiredNonRecurringRule() throws Exception {
    // applyRules should delete non-recurring rules for dates before the current
    // date.//from   w  w w. ja v a 2  s.c  om

    // ARRANGE
    initialiseRuleManager();

    // Set the current date to a date after an existing non-recurring rule, but
    // also for a day-of-the-week when no other rules apply (just to avoid extra
    // createBooking noise):
    String thursday = existingThursdayNonRecurringRule.getBooking().getDate();
    String dayAfterThursday = LocalDate.parse(thursday, DateTimeFormatter.ofPattern("yyyy-MM-dd")).plusDays(4)
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    ruleManager
            .setCurrentLocalDate(LocalDate.parse(dayAfterThursday, DateTimeFormatter.ofPattern("yyyy-MM-dd")));

    expectOptimisticPersisterToReturnVersionedAttributes(42);
    expectPurgeExpiredRulesAndRuleExclusions(42, existingBookingRules,
            Optional.of(existingThursdayNonRecurringRule), Optional.empty());

    // ACT
    // This should delete the (expired) Thursday rule
    ruleManager.applyRules(dayAfterThursday, false);
}

From source file:squash.booking.lambdas.core.RuleManagerTest.java

@Test
public void testApplyRulesCallsBookingManagerCorrectly_PurgeExpiredRuleExclusions() throws Exception {
    // applyRules should delete rule exclusions for dates before the current
    // day./*  www.j  ava2 s  .  c  om*/

    // ARRANGE
    initialiseRuleManager();

    // Set the current date to a date after an exclusion, but also for a
    // day-of-the-week when no other rules apply (just to avoid extra
    // createBooking noise):
    String exclusionDate = existingSaturdayRecurringRuleWithExclusion.getDatesToExclude()[0];
    String daysAfterExclusionDate = LocalDate.parse(exclusionDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
            .plusDays(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    ruleManager.setCurrentLocalDate(
            LocalDate.parse(daysAfterExclusionDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));

    expectOptimisticPersisterToReturnVersionedAttributes(42);
    expectPurgeExpiredRulesAndRuleExclusions(42, existingBookingRules,
            Optional.of(existingThursdayNonRecurringRule),
            Optional.of(new ImmutablePair<>(existingSaturdayRecurringRuleWithExclusion, exclusionDate)));

    // ACT
    // This should delete the (expired) Thursday rule
    ruleManager.applyRules(daysAfterExclusionDate, false);
}