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:squash.booking.lambdas.GetBookingsLambdaTest.java

@Before
public void beforeTest() throws Exception {
    mockery = new Mockery();
    getBookingsLambda = new TestGetBookingsLambda();
    getBookingsLambda.setBookingManager(mockery.mock(IBookingManager.class));

    // Set up the valid date range
    List<String> validDates = new ArrayList<>();
    fakeCurrentDate = LocalDate.of(2015, 10, 6);
    fakeCurrentDateString = fakeCurrentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    validDates.add(fakeCurrentDateString);
    validDates.add(fakeCurrentDate.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    getBookingsLambda.setValidDates(validDates);

    // Set up mock context
    mockContext = mockery.mock(Context.class);
    mockery.checking(new Expectations() {
        {/*  w w  w  .  j a  va 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() {
        {
            allowing(mockLifecycleManager).getLifecycleState();
            will(returnValue(new ImmutablePair<LifecycleState, Optional<String>>(LifecycleState.ACTIVE,
                    Optional.empty())));
        }
    });
    getBookingsLambda.setLifecycleManager(mockLifecycleManager);

    // Set up some typical bookings data that the tests can use
    name = "A.Playera/B.Playerb";
    court = 5;
    slot = 3;
    booking = new Booking(court, slot, name);
    bookings = new ArrayList<>();
    bookings.add(booking);
    redirectUrl = "redirectUrl.html";

    // Exception message thrown to apigateway invocations has a redirecturl
    // appended
    genericExceptionMessage = "Apologies - something has gone wrong. Please try again." + redirectUrl;
}

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

@Test(expected = IllegalArgumentException.class)
public void createAgentWithWrongName() throws Exception {
    Agent agent = newAgent(null, LocalDate.of(1950, 1, 1));
    manager.createAgent(agent);/*  ww w  .  j a  v  a 2s . c  o m*/
}

From source file:me.yanaga.querydsl.args.core.single.SingleComparableArgumentTest.java

@Test
public void testAppendGoeWithTwoArguments() {
    SingleComparableArgument<CustomComparableType> argument = SingleComparableArgument
            .of(CustomComparableType.of(LocalDate.of(2015, 3, 30)));
    BooleanBuilder builder = new BooleanBuilder();
    argument.append(builder, QPerson.person.oneCustomComparableType,
            QPerson.person.anotherCustomComparableType);
    Person result = new JPAQuery(entityManager).from(QPerson.person).where(builder)
            .uniqueResult(QPerson.person);
    assertThat(result).isNull();/* w  w  w  .j  a va2 s . c om*/
}

From source file:ch.algotrader.dao.security.FutureDaoImpl.java

@Override
public Future findByMonthYear(long futureFamilyId, int year, int month) {

    LocalDate date = LocalDate.of(year, month, 1);
    String monthYear = DateTimePatterns.MONTH_YEAR.format(date);
    return findUniqueCaching("Future.findByMonthYear", QueryType.BY_NAME,
            new NamedParam("futureFamilyId", futureFamilyId), new NamedParam("monthYear", monthYear));
}

From source file:se.nrm.dina.naturarv.portal.controller.MainChart.java

/**
 * Initiate date now//from   ww  w.  ja v  a  2  s.c  o m
 */
private void initDate() {
    log.info("initDate");

    isSwedish = language.isIsSwedish();
    today = LocalDate.now();
    year = today.getYear();
    lastYear = year - 1;
    month = today.getMonthValue();

    lastYearDate = LocalDate.of(lastYear, month, today.getDayOfMonth());
    lastTenYear = year - 10;
}

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

@Test
public void shouldEncodeBlogpost() throws IOException, JSONException {
    // given//  w w w  . jav a  2s  .  co  m
    final Blogpost blogpost = new Blogpost();
    blogpost.setId(1L);
    blogpost.setTitle("blog post");
    blogpost.setContent("Lorem ipsum...");
    blogpost.setTags(new String[] { "foo", "bar" });
    final Comment firstComment = new Comment("Xavier", "Nice work!", 5, LocalDate.of(2016, 4, 1));
    final Comment secondComment = new Comment("Xavier", "this looks good", 5, LocalDate.of(2016, 7, 3));
    blogpost.setComments(Arrays.asList(firstComment, secondComment));
    // when
    final String actualContent = new DocumentCodec<>(Blogpost.class, ObjectMapperFactory.getObjectMapper())
            .encode(blogpost);
    // then id should not be part of the documentSource, but other fields, yes.
    final String expectedContent = IOUtils
            .toString(BikeStationDeserializer.class.getClassLoader().getResource("blogpost.json"));
    JSONAssert.assertEquals(expectedContent, actualContent, false);
}

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

@Test
public void getAllAgents() {

    assertTrue(manager.findAllAgents().isEmpty());

    Agent a1 = newAgent("Agent Smith", LocalDate.of(1969, 12, 12));
    Agent a2 = newAgent("James Bond", LocalDate.of(1950, 1, 1));

    manager.createAgent(a1);//  w w  w. j  a  v a 2 s. c  om
    manager.createAgent(a2);

    List<Agent> expected = Arrays.asList(a1, a2);
    List<Agent> actual = manager.findAllAgents();

    Collections.sort(actual, idComparator);
    Collections.sort(expected, idComparator);

    assertEquals("saved and retrieved agents differ", expected, actual);
    assertDeepEquals(expected, actual);
}

From source file:org.ojbc.adapters.analyticaldatastore.personid.IndexedPersonIdentifierStrategyTest.java

private Object makeDate(int year, int monthOfYear, int dayOfMonth) {
    LocalDate today = LocalDate.of(year, monthOfYear, dayOfMonth);
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd");
    String dateTimeStamp = today.format(dtf);

    return dateTimeStamp;
}

From source file:de.steilerdev.myVerein.server.controller.admin.EventManagementController.java

/**
 * This function gathers all dates where an event takes place within a specific month and year. The function is invoked by GETting the URI /api/admin/event/month and specifying the month and year via the request parameters.
 * @param month The selected month.//from   ww  w  .  j  av  a2 s.co m
 * @param year The selected year.
 * @return An HTTP response with a status code. If the function succeeds, a list of dates, during the month, that contain an event, is returned, otherwise an error code is returned.
 */
@RequestMapping(value = "month", produces = "application/json", method = RequestMethod.GET)
public ResponseEntity<List<LocalDate>> getEventDatesOfMonth(@RequestParam String month,
        @RequestParam String year, @CurrentUser User currentUser) {
    logger.trace("[" + currentUser + "] Gathering events of month " + month + " and year " + year);
    ArrayList<LocalDate> dates = new ArrayList<>();
    int monthInt, yearInt;
    try {
        monthInt = Integer.parseInt(month);
        yearInt = Integer.parseInt(year);
    } catch (NumberFormatException e) {
        logger.warn("[" + currentUser + "] Unable to parse month or year.");
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    LocalDateTime start = LocalDate.of(yearInt, monthInt, 1).atStartOfDay();
    LocalDateTime end = start.plusMonths(1);

    logger.debug("Getting all single day events...");
    dates.addAll(eventRepository.findAllByEndDateTimeBetweenAndMultiDate(start, end, false).parallelStream()
            .map(Event::getStartDate).collect(Collectors.toList()));
    logger.debug("All single day events retrieved, got " + dates.size() + " dates so far");

    logger.debug("Getting all multi day events...");
    //Collecting all multi date events, that either start or end within the selected month (which means that events that are spanning over several months are not collected)
    Stream.concat(eventRepository.findAllByStartDateTimeBetweenAndMultiDate(start, end, true).stream(), //All multi date events starting within the month
            eventRepository.findAllByEndDateTimeBetweenAndMultiDate(start, end, true).stream()) //All multi date events ending within the month
            .distinct() //Removing all duplicated events
            .parallel().forEach(event -> { //Creating a local date for each occupied date of the event
                for (LocalDate date = event.getStartDate(); //Starting with the start date
                        !date.equals(event.getEndDateTime().toLocalDate()); //Until reaching the end date
                        date = date.plusDays(1)) //Adding a day within each iterations
                {
                    dates.add(date);
                }
                dates.add(event.getEndDateTime().toLocalDate()); //Finally adding the last date
            });
    logger.debug("All multi day events gathered, got " + dates.size() + " dates so far");

    if (dates.isEmpty()) {
        logger.warn("[" + currentUser + "] Returning empty dates list of " + month + "/" + year);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        logger.debug("[" + currentUser + "] Returning dates list " + month + "/" + year);
        return new ResponseEntity<>(dates.stream().distinct().collect(Collectors.toList()), HttpStatus.OK); //Returning an optimized set of events
    }
}

From source file:no.digipost.api.useragreements.client.Examples.java

public void get_invoices() {
    final SenderId senderId = SenderId.of(1234L);
    final UserId userId = UserId.of("01017012345");

    final List<Document> unpaidInvoice = client.getDocuments(senderId, INVOICE_BANK, userId,
            GetDocumentsQuery.empty());/*  w w w. ja va  2s .  c o m*/

    final List<Document> allOptions = client.getDocuments(senderId, INVOICE_BANK, userId,
            GetDocumentsQuery.builder().invoiceStatus(InvoiceStatus.PAID)
                    .invoiceDueDateFrom(LocalDate.of(2017, 1, 1)).invoiceDueDateTo(LocalDate.of(2017, 5, 1))
                    .build());
}