Example usage for java.time ZonedDateTime plusSeconds

List of usage examples for java.time ZonedDateTime plusSeconds

Introduction

In this page you can find the example usage for java.time ZonedDateTime plusSeconds.

Prototype

public ZonedDateTime plusSeconds(long seconds) 

Source Link

Document

Returns a copy of this ZonedDateTime with the specified number of seconds added.

Usage

From source file:nu.yona.server.analysis.service.AnalysisEngineServiceTest.java

@Test
public void analyze_unorderedAppActivity_addedOrdered() {
    JUnitUtil.skipBefore("Skip shortly after midnignt", now(), 0, 10);
    String app = "Poker App";
    ZonedDateTime today = now().truncatedTo(ChronoUnit.DAYS);
    ZonedDateTime t1 = today.withHour(0).withMinute(0).withSecond(1);
    ZonedDateTime t2 = t1.plusSeconds(15);
    ZonedDateTime t3 = t2.plusSeconds(1);
    ZonedDateTime t4 = t3.plusMinutes(5);

    service.analyze(userAnonId, deviceAnonId, new AppActivitiesDto(now(), new AppActivitiesDto.Activity[] {
            new AppActivitiesDto.Activity(app, t3, t4), new AppActivitiesDto.Activity(app, t1, t2) }));

    ArgumentCaptor<ActivityPayload> activityPayloadCaptor = ArgumentCaptor.forClass(ActivityPayload.class);
    verify(mockActivityUpdater, times(2)).addActivity(any(), activityPayloadCaptor.capture(),
            eq(GoalDto.createInstance(gamblingGoal)), any());
    List<ActivityPayload> payloads = activityPayloadCaptor.getAllValues();
    assertThat(payloads.size(), equalTo(2));
    assertThat(payloads.get(0).startTime, equalTo(t1));
    assertThat(payloads.get(0).endTime, equalTo(t2));
    assertThat(payloads.get(1).startTime, equalTo(t3));
    assertThat(payloads.get(1).endTime, equalTo(t4));
    verify(mockActivityUpdater, never()).updateTimeExistingActivity(any(), any());
    verify(mockActivityUpdater, never()).updateTimeLastActivity(any(), any(), any());
}

From source file:nu.yona.server.analysis.service.AnalysisEngineServiceTest.java

@Test
public void analyze_appActivitySameAppWithinConflictIntervalButNotContinuous_addActivity() {
    ZonedDateTime now = now();//  ww w . j  a v a 2 s. co m
    JUnitUtil.skipBefore("Skip shortly after midnight", now, 0, 11);
    ZonedDateTime existingActivityEndTime = now.minusMinutes(5);
    mockExistingActivity(gamblingGoal, now.minusMinutes(10), now.minusMinutes(5), "Lotto App");

    service.analyze(userAnonId, deviceAnonId,
            createSingleAppActivity("Lotto App", existingActivityEndTime.plusSeconds(1), now.minusMinutes(2)));

    verify(mockActivityUpdater).addActivity(any(), any(), eq(GoalDto.createInstance(gamblingGoal)), any());
}

From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java

@Test
public void ableToPostDate() throws Exception {
    ZonedDateTime date = ZonedDateTime.now().truncatedTo(SECONDS);
    MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("date",
            RestObjectMapperFactory.getRestObjectMapper().convertToString(Date.from(date.toInstant())));

    HttpHeaders headers = new HttpHeaders();
    headers.add(CONTENT_TYPE, APPLICATION_FORM_URLENCODED_VALUE);

    int seconds = 1;
    Date result = restTemplate.postForObject(codeFirstUrl + "addDate?seconds={seconds}",
            new HttpEntity<>(body, headers), Date.class, seconds);

    assertThat(result, is(Date.from(date.plusSeconds(seconds).toInstant())));

    ListenableFuture<ResponseEntity<Date>> listenableFuture = asyncRestTemplate.postForEntity(
            codeFirstUrl + "addDate?seconds={seconds}", new HttpEntity<>(body, headers), Date.class, seconds);
    ResponseEntity<Date> dateResponseEntity = listenableFuture.get();
    assertThat(dateResponseEntity.getBody(), is(Date.from(date.plusSeconds(seconds).toInstant())));
}