Example usage for java.time LocalDate of

List of usage examples for java.time LocalDate of

Introduction

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

Prototype

public static LocalDate of(int year, int month, int dayOfMonth) 

Source Link

Document

Obtains an instance of LocalDate from a year, month and day.

Usage

From source file:cz.muni.fi.pv168.AgentManagerImplTest.java

@Test
public void deleteAgent() {

    Agent a1 = newAgent("Agent Smith", LocalDate.of(1969, 12, 12));
    Agent a2 = newAgent("James Bond", LocalDate.of(1950, 1, 1));
    manager.createAgent(a1);//from   w  w w .j  a v a 2s.co m
    manager.createAgent(a2);

    assertNotNull(manager.getAgent(a1.getId()));
    assertNotNull(manager.getAgent(a2.getId()));

    manager.deleteAgent(a1);

    assertNull(manager.getAgent(a1.getId()));
    assertNotNull(manager.getAgent(a2.getId()));

}

From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java

@Test
public void aggregateMoreDays() throws Exception {
    LocalDate from = LocalDate.of(2015, 9, 1);
    LocalDate to = LocalDate.of(2015, 9, 2);
    eventAggregator.aggregateDay(from, to);
    verify(eventDataReader).read(eq(2015), eq(9), eq(1), any(Consumer.class));
    verify(eventDataReader).read(eq(2015), eq(9), eq(2), any(Consumer.class));
}

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

@Before
public void beforeTest() throws Exception {
    fakeCurrentDate = LocalDate.of(2015, 10, 6);
    fakeCurrentDateString = fakeCurrentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    validDates = new ArrayList<>();
    validDates.add(fakeCurrentDateString);
    validDates.add(fakeCurrentDate.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));

    pageManager = new squash.booking.lambdas.core.PageManagerTest.TestPageManager();
    pageManager.setCurrentLocalDate(fakeCurrentDate);

    activeLifecycleState = Optional
            .of(new ImmutablePair<LifecycleState, Optional<String>>(LifecycleState.ACTIVE, Optional.empty()));
    mockery = new Mockery();
    // Set up mock context
    mockContext = mockery.mock(Context.class);
    mockery.checking(new Expectations() {
        {/* w  w  w. j ava  2 s . co m*/
            ignoring(mockContext);
        }
    });
    // Set up mock logger
    mockLogger = mockery.mock(LambdaLogger.class);
    mockery.checking(new Expectations() {
        {
            ignoring(mockLogger);
        }
    });
    // Set up mock booking manager
    mockBookingManager = mockery.mock(IBookingManager.class);
    mockery.checking(new Expectations() {
        {
            ignoring(mockBookingManager);
        }
    });
    // Set up mock lifecycle manager
    mockLifecycleManager = mockery.mock(ILifecycleManager.class);
    mockery.checking(new Expectations() {
        {
            // Some page manager methods query for lifecycle state - return ACTIVE
            // state by default.
            allowing(mockLifecycleManager).getLifecycleState();
            will(returnValue(activeLifecycleState.get()));
            ignoring(mockLifecycleManager);
        }
    });

    websiteBucketName = "websiteBucketName";
    pageManager.setS3WebsiteBucketName(websiteBucketName);

    // Use a single booking for most of the tests
    court = 5;
    courtSpan = 1;
    slot = 12;
    slotSpan = 1;
    name = "D.Playerd/F.Playerf";
    booking = new Booking(court, courtSpan, slot, slotSpan, name);
    bookings = new ArrayList<>();
    bookings.add(booking);

    revvingSuffix = "revvingSuffix";

    apiGatewayBaseUrl = "apiGatewayBaseUrl";
    adminSnsTopicArn = "adminSnsTopicArn";
    pageManager.setAdminSnsTopicArn(adminSnsTopicArn);
}

From source file:org.jboss.jbossset.JiraReporterTest.java

@Test(expected = ParseException.class)
public void testStartAfterEndDate() throws ParseException {
    String cmd = "-u user1 -s " + LocalDate.of(2015, 2, 1) + " -e " + LocalDate.of(2015, 1, 1);
    new CommandLineParser(cmd.split(" ")).parse();
}

From source file:com.bofa.sstradingreport.managementreport.TradeReportControllerTest.java

@Test
public void shouldgetTradeReports() throws Exception {
    final List<TradeReportEntity> allbikes = Arrays.asList(
            Reflect.on(TradeReportEntity.class).create().set("id", 4711).set("name", "Bike 1")
                    .set("tradeDate",
                            GregorianCalendar.from(
                                    LocalDate.of(2015, Month.JANUARY, 1).atStartOfDay(ZoneId.systemDefault())))
                    .call("getTradeReport").get(),
            Reflect.on(TradeReportEntity.class).create().set("id", 23)
                    .set("tradeDate",
                            GregorianCalendar.from(
                                    LocalDate.of(2014, Month.JANUARY, 1).atStartOfDay(ZoneId.systemDefault())))
                    .call("getTradeReport").get());
    final List<TradeReportEntity> activeBikes = Arrays.asList(allbikes.get(0));

    final TradeReportRepository repository = mock(TradeReportRepository.class);
    stub(repository.findAll(any(Sort.class))).toReturn(allbikes);
    //   stub(repository.findByDecaommissionedOnIsNull(any(Sort.class))).toReturn(activeBikes);

    final TradeReportController controller = new TradeReportController(repository);

    final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller)
            .setControllerAdvice(new ExceptionHandlerAdvice())
            .apply(documentationConfiguration(this.restDocumentation)).build();

    mockMvc.perform(get("http://localhost:8088/sstradingreport/api/bikes").param("all", "true"))
            .andExpect(status().isOk()).andExpect(content().string(objectMapper.writeValueAsString(allbikes)))
            .andDo(document("api/bikes/get", preprocessRequest(prettyPrint()),
                    preprocessResponse(prettyPrint()),
                    requestParameters(parameterWithName("all").description(
                            "Flag, if all bikes, including decommissioned bikes, should be returned.")),
                    responseFields(fieldWithPath("[]").description("An array of bikes"),
                            fieldWithPath("[].id").description("The unique Id of the bike"),
                            fieldWithPath("[].name").description("The name of the bike"),
                            fieldWithPath("[].tradeDate").description("The date the bike was bought"))));

    mockMvc.perform(get("http://biking.michael-simons.eu/api/bikes")).andExpect(status().isOk())
            .andExpect(content().string(objectMapper.writeValueAsString(activeBikes)));

    Mockito.verify(repository).findAll(Mockito.any(Sort.class));
    //   Mockito.verify(repository).findByDecommissionedOnIsNull(Mockito.any(Sort.class));
    verifyNoMoreInteractions(repository);
}

From source file:com.qwazr.externalizor.SimpleTime.java

public SimpleTime() {

    calNullValue = null;/*from   w  ww  .j  a v  a2 s .c  om*/
    calValue = Calendar.getInstance();
    calValue.setTimeInMillis(RandomUtils.nextLong());
    calArray = new Calendar[] { calNullValue, calValue };
    calList = new ArrayList(Arrays.asList(calValue, calNullValue));

    dateNullValue = null;
    dateValue = new Date(RandomUtils.nextLong());
    dateArray = new Date[] { dateNullValue, dateValue };
    dateList = new ArrayList(Arrays.asList(dateValue, dateNullValue));

    durationNullValue = null;
    durationValue = Duration.ofSeconds(RandomUtils.nextLong());
    durationArray = new Duration[] { durationNullValue, durationValue };
    durationList = new ArrayList(Arrays.asList(durationValue, durationNullValue));

    instantNullValue = null;
    instantValue = Instant.ofEpochSecond(RandomUtils.nextLong(0, Instant.MAX.getEpochSecond()));
    instantArray = new Instant[] { instantNullValue, instantValue };
    instantList = new ArrayList(Arrays.asList(instantValue, instantNullValue));

    localTimeNullValue = null;
    localTimeValue = LocalTime.of(RandomUtils.nextInt(0, 24), RandomUtils.nextInt(0, 60),
            RandomUtils.nextInt(0, 60));
    localTimeArray = new LocalTime[] { localTimeNullValue, localTimeValue };
    localTimeList = new ArrayList(Arrays.asList(localTimeValue, localTimeNullValue));

    localDateNullValue = null;
    localDateValue = LocalDate.of(RandomUtils.nextInt(2000, 3000), RandomUtils.nextInt(1, 13),
            RandomUtils.nextInt(1, 29));
    localDateArray = new LocalDate[] { localDateNullValue, localDateValue };
    localDateList = new ArrayList(Arrays.asList(localDateValue, localDateNullValue));

    localDateTimeNullValue = null;
    localDateTimeValue = LocalDateTime.of(
            LocalDate.of(RandomUtils.nextInt(2000, 3000), RandomUtils.nextInt(1, 13),
                    RandomUtils.nextInt(1, 29)),
            LocalTime.of(RandomUtils.nextInt(0, 24), RandomUtils.nextInt(0, 60), RandomUtils.nextInt(0, 60)));
    localDateTimeArray = new LocalDateTime[] { localDateTimeNullValue, localDateTimeValue };
    localDateTimeList = new ArrayList(Arrays.asList(localDateTimeValue, localDateTimeNullValue));

    monthDayNullValue = null;
    monthDayValue = MonthDay.of(RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 29));
    monthDayArray = new MonthDay[] { monthDayNullValue, monthDayValue };
    monthDayList = new ArrayList(Arrays.asList(monthDayValue, monthDayNullValue));

    periodNullValue = null;
    periodValue = Period.of(RandomUtils.nextInt(0, Year.MAX_VALUE), RandomUtils.nextInt(1, 13),
            RandomUtils.nextInt(1, 29));
    periodArray = new Period[] { periodNullValue, periodValue };
    periodList = new ArrayList(Arrays.asList(periodValue, periodNullValue));

    yearNullValue = null;
    yearValue = Year.of(RandomUtils.nextInt(0, Year.MAX_VALUE));
    yearArray = new Year[] { yearNullValue, yearValue };
    yearList = new ArrayList(Arrays.asList(yearValue, yearNullValue));

}

From source file:cz.muni.fi.pv168.AgentManagerImplTest.java

@Test(expected = IllegalArgumentException.class)
public void deleteAgentNull() throws Exception {
    Agent agent = newAgent("James Bond", LocalDate.of(1950, 1, 1));
    manager.deleteAgent(null);/*from w  ww . ja  va  2  s  . co  m*/
}

From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java

@Test
public void testCreateReservation() {
    LocalDate checkin = LocalDate.of(2016, 8, 7);
    LocalDate checkout = LocalDate.of(2016, 8, 11);
    LocalDate reservationdate = LocalDate.now(prepareClockMock(now));

    Reservation reservation = setReservation(1, 1, checkin, checkout, reservationdate);
    reservationManager.createReservation(reservation);

    Long reservationId = reservation.getReservationId();
    assertNotNull(reservationId);//www  .  j a  v  a  2 s.  com

    Reservation result = reservationManager.findReservation(reservationId);
    assertThat("loaded reservation differs from the saved one", result, is(equalTo(reservation)));
    assertThat("loaded reservation is the same instance", result, is(not(sameInstance(reservation))));
    assertDeepEquals(reservation, result);
}

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

@Before
public void beforeTest() {
    // Set up the valid date range
    fakeCurrentDate = LocalDate.of(2015, 10, 6);
    fakeCurrentDateString = fakeCurrentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    bookingManager = new squash.booking.lambdas.core.BookingManagerTest.TestBookingManager();
    bookingManager.setCurrentLocalDate(fakeCurrentDate);

    // Set up the test bookings
    existingName = "A.Shabana/J.Power";
    newName = "J.Willstrop/N.Matthew";
    existingSingleBooking = new Booking(2, 1, 3, 1, existingName);
    existingSingleBooking.setDate(fakeCurrentDateString);
    blockBookingOverlappingExistingSingleBooking = new Booking(1, 3, 3, 2, newName);
    blockBookingOverlappingExistingSingleBooking.setDate(fakeCurrentDateString);
    blockBookingOverlappingExistingBlockBooking = new Booking(2, 2, 9, 2, newName);
    blockBookingOverlappingExistingBlockBooking.setDate(fakeCurrentDateString);
    singleBookingOfFreeCourt = new Booking(4, 1, 12, 1, newName);
    singleBookingOfFreeCourt.setDate(fakeCurrentDateString);
    existingBlockBooking = new Booking(3, 3, 10, 2, existingName);
    existingBlockBooking.setDate(fakeCurrentDateString);
    singleBookingWithinExistingBlockBooking = new Booking(4, 1, 11, 1, newName);
    singleBookingWithinExistingBlockBooking.setDate(fakeCurrentDateString);
    blockBookingOfFreeCourts = new Booking(1, 5, 13, 3, newName);
    blockBookingOfFreeCourts.setDate(fakeCurrentDateString);
    bookingsBeforeCall = new ArrayList<>();
    bookingsBeforeCall.add(existingSingleBooking);
    bookingsBeforeCall.add(existingBlockBooking);
    expectedBookingsAfterCall = new ArrayList<>();

    mockery = new Mockery();
    // Set up mock context
    mockContext = mockery.mock(Context.class);
    mockery.checking(new Expectations() {
        {/*from w  w  w.  j av  a  2  s . c  o  m*/
            ignoring(mockContext);
        }
    });
    // Set up mock logger
    mockLogger = mockery.mock(LambdaLogger.class);
    mockery.checking(new Expectations() {
        {
            ignoring(mockLogger);
        }
    });
    // Set up mock lifecycle manager
    mockLifecycleManager = mockery.mock(ILifecycleManager.class);
    mockery.checking(new Expectations() {
        {
            ignoring(mockLifecycleManager);
        }
    });
    bookingManager.setLifecycleManager(mockLifecycleManager);
    mockOptimisticPersister = mockery.mock(IOptimisticPersister.class);
    bookingManager.setOptimisticPersister(mockOptimisticPersister);
    adminSnsTopicArn = "adminSnsTopicArn";
    bookingManager.setAdminSnsTopicArn(adminSnsTopicArn);
}

From source file:org.lambdamatic.internal.elasticsearch.codec.DocumentCodecTest.java

@Test
public void shouldDecodeBlogPost() throws JsonParseException, JsonMappingException, IOException {
    // given//  ww w.ja va2  s.  c o  m
    final InputStream content = BikeStationDeserializer.class.getClassLoader()
            .getResourceAsStream("blogpost.json");
    // when
    final Blogpost blogpost = ObjectMapperFactory.getObjectMapper().readValue(content, Blogpost.class);
    // then
    assertThat(blogpost.getId()).isNull();
    assertThat(blogpost.getTitle()).isEqualTo("blog post");
    assertThat(blogpost.getContent()).isEqualTo("Lorem ipsum...");
    assertThat(blogpost.getTags()).containsExactly("foo", "bar");
    assertThat(blogpost.getComments()).containsExactly(
            new Comment("Xavier", "Nice work!", 5, LocalDate.of(2016, 04, 01)),
            new Comment("Xavier", "this looks good", 5, LocalDate.of(2016, 07, 03)));
}