本文整理汇总了Java中java.time.Duration.ofDays方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.ofDays方法的具体用法?Java Duration.ofDays怎么用?Java Duration.ofDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.ofDays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: thatPushNotificationIsSentWhenLastThresholdWasPassedAndNoNotificationWasEverSent
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndNoNotificationWasEverSent() throws Exception {
Duration firstThreshold = Duration.ofDays(1);
Duration secondThreshold = Duration.ofDays(2);
Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);
when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.empty());
when(clock.instant()).thenReturn(disconnectInstant);
offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));
when(clock.instant()).thenReturn(jobRunInstant);
offlineDevicesJob.run();
verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:21,代码来源:OfflineDevicesJobTests.java
示例2: thatPushNotificationIsNotSentWhenSingleThresholdWasPassedButNotificationWasAlreadySent
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void thatPushNotificationIsNotSentWhenSingleThresholdWasPassedButNotificationWasAlreadySent() throws Exception {
Duration threshold = Duration.ofDays(1);
Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
Instant lastOfflineNotificationInstant = disconnectInstant.plus(threshold).plusSeconds(1);
Instant jobRunInstant = disconnectInstant.plus(threshold).plusSeconds(2);
when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));
when(clock.instant()).thenReturn(disconnectInstant);
offlineDevicesJob.onConfigurationUpdate(Collections.singletonList(threshold));
offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));
when(clock.instant()).thenReturn(jobRunInstant);
offlineDevicesJob.run();
verify(pushNotificationService, never()).sendOfflineNotification(any(Device.class));
}
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:21,代码来源:OfflineDevicesJobTests.java
示例3: thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold() throws Exception {
Duration firstThreshold = Duration.ofDays(1);
Duration secondThreshold = Duration.ofDays(2);
Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
Instant lastOfflineNotificationInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);
Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);
when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));
when(clock.instant()).thenReturn(disconnectInstant);
offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));
when(clock.instant()).thenReturn(jobRunInstant);
offlineDevicesJob.run();
verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:22,代码来源:OfflineDevicesJobTests.java
示例4: shouldNotAuthenticateIfRequestIsNot200
import java.time.Duration; //导入方法依赖的package包/类
@Test(expected = GithubAuthenticationException.class)
public void shouldNotAuthenticateIfRequestIsNot200() throws Exception {
HttpClient mockClient = Mockito.mock(HttpClient.class);
HttpResponse mockRespone = Mockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(mockRespone.getStatusLine().getStatusCode()).thenReturn(403);
Mockito.when(mockClient.execute(Mockito.any())).thenReturn(mockRespone);
GithubApiClient clientToTest = new GithubApiClient(mockClient, new MockGithubOauthConfiguration(Duration.ofDays(1)));
clientToTest.authz("demo-user", "DUMMY".toCharArray());
}
示例5: convert
import java.time.Duration; //导入方法依赖的package包/类
@Override
public Duration convert(String source) {
source = source.trim();
if ("0".equals(source)) {
return Duration.ZERO;
}
Matcher matcher = pattern.matcher(source);
if (!matcher.matches()) throw new IllegalArgumentException("Illegal period: " + source);
long value = Long.parseLong(matcher.group(1));
switch (matcher.group(2).toLowerCase()) {
case "ns":
case "nanos":
return Duration.ofNanos(value);
case "ms":
case "msec":
case "millis":
return Duration.ofMillis(value);
case "s":
case "sec":
return Duration.ofSeconds(value);
case "m":
case "min":
return Duration.ofMinutes(value);
case "h":
case "hour":
case "hours":
return Duration.ofHours(value);
case "d":
case "day":
case "days":
return Duration.ofDays(value);
}
throw new IllegalArgumentException("Illegal unit: " + source);
}
示例6: data_minus_TemporalAmount
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
return new Object[][] {
{YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
{YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
{YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
{YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
};
}
示例7: sendMessageWithSchedule
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void sendMessageWithSchedule() throws Exception {
String msgData = "data";
FutureTimepoint tomorrow = new FutureTimepoint(Duration.ofDays(1));
ChannelMessage<FutureTimepoint, String> msg =
message(tomorrow, msgData);
target.send(msg);
assertHasSentMessage(QMessageType.Durable, msgData);
assertThat(builtMsg.schedule, is(tomorrow));
}
示例8: thatNoPushNotificationIsSentWhenNoThresholdWasPassed
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void thatNoPushNotificationIsSentWhenNoThresholdWasPassed() {
Duration threshold = Duration.ofDays(1);
when(clock.instant()).thenReturn(Instant.now());
offlineDevicesJob.onConfigurationUpdate(Collections.singletonList(threshold));
offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));
offlineDevicesJob.run();
verify(pushNotificationService, never()).sendOfflineNotification(any(Device.class));
}
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:13,代码来源:OfflineDevicesJobTests.java
示例9: data_minusInvalidUnit
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="minusInvalidUnit")
Object[][] data_minusInvalidUnit() {
return new Object[][] {
{Period.of(0, 1, 0)},
{Period.of(0, 0, 1)},
{Period.of(0, 1, 1)},
{Period.of(1, 1, 1)},
{Duration.ofDays(1)},
{Duration.ofHours(1)},
{Duration.ofMinutes(1)},
{Duration.ofSeconds(1)},
};
}
示例10: parseCacheAge
import java.time.Duration; //导入方法依赖的package包/类
private void parseCacheAge() {
String s = this.cacheAge.getText();
this.maxAge = s.isEmpty() ? Duration.ofDays(1) : StringUtil.parseDuration(s);
this.genEnd.setDisable(this.maxAge.equals(Duration.ZERO));
}
示例11: plusDays_long
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="PlusDays")
public void plusDays_long(long days, long amount, long expectedDays) {
Duration t = Duration.ofDays(days);
t = t.plusDays(amount);
assertEquals(t.toDays(), expectedDays);
}
示例12: minusDays_long
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="MinusDays")
public void minusDays_long(long days, long amount, long expectedDays) {
Duration t = Duration.ofDays(days);
t = t.minusDays(amount);
assertEquals(t.toDays(), expectedDays);
}
示例13: factory_days_tooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void factory_days_tooBig() {
Duration.ofDays(Long.MAX_VALUE / 86400 + 1);
}
示例14: factory_days_tooSmall
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void factory_days_tooSmall() {
Duration.ofDays(Long.MIN_VALUE / 86400 - 1);
}
示例15: minusDays_long_overflowTooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions = {ArithmeticException.class})
public void minusDays_long_overflowTooBig() {
Duration t = Duration.ofDays(Long.MAX_VALUE/3600/24);
t.minusDays(-1);
}