Commit fac6f08c authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Use new AssertJ duration assertions

See gh-19985
parent 7de3712e
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -40,7 +40,7 @@ public abstract class PushRegistryPropertiesConfigAdapterTests<P extends PushReg ...@@ -40,7 +40,7 @@ public abstract class PushRegistryPropertiesConfigAdapterTests<P extends PushReg
void whenPropertiesStepIsSetAdapterStepReturnsIt() { void whenPropertiesStepIsSetAdapterStepReturnsIt() {
P properties = createProperties(); P properties = createProperties();
properties.setStep(Duration.ofSeconds(42)); properties.setStep(Duration.ofSeconds(42));
assertThat(createConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(42)); assertThat(createConfigAdapter(properties).step()).hasSeconds(42);
} }
@Test @Test
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -83,7 +83,7 @@ class JmsPropertiesTests { ...@@ -83,7 +83,7 @@ class JmsPropertiesTests {
@Test @Test
void defaultReceiveTimeoutMatchesListenerContainersDefault() { void defaultReceiveTimeoutMatchesListenerContainersDefault() {
assertThat(new JmsProperties().getListener().getReceiveTimeout()) assertThat(new JmsProperties().getListener().getReceiveTimeout())
.isEqualTo(Duration.ofMillis(AbstractPollingMessageListenerContainer.DEFAULT_RECEIVE_TIMEOUT)); .hasMillis(AbstractPollingMessageListenerContainer.DEFAULT_RECEIVE_TIMEOUT);
} }
} }
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.session; package org.springframework.boot.autoconfigure.session;
import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
...@@ -98,8 +97,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest ...@@ -98,8 +97,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
this.contextRunner this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class) .withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=1", "spring.session.timeout=3") .withPropertyValues("server.servlet.session.timeout=1", "spring.session.timeout=3")
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()) .run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()).hasSeconds(3));
.isEqualTo(Duration.ofSeconds(3)));
} }
@Test @Test
...@@ -107,8 +105,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest ...@@ -107,8 +105,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
this.contextRunner this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class) .withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=3") .withPropertyValues("server.servlet.session.timeout=3")
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()) .run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()).hasSeconds(3));
.isEqualTo(Duration.ofSeconds(3)));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,7 +20,6 @@ import java.io.IOException; ...@@ -20,7 +20,6 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -107,7 +106,7 @@ class ServerPropertiesTests { ...@@ -107,7 +106,7 @@ class ServerPropertiesTests {
@Test @Test
void testConnectionTimeout() { void testConnectionTimeout() {
bind("server.connection-timeout", "60s"); bind("server.connection-timeout", "60s");
assertThat(this.properties.getConnectionTimeout()).isEqualTo(Duration.ofMillis(60000)); assertThat(this.properties.getConnectionTimeout()).hasMillis(60000);
} }
@Test @Test
...@@ -149,7 +148,7 @@ class ServerPropertiesTests { ...@@ -149,7 +148,7 @@ class ServerPropertiesTests {
assertThat(tomcat.getRemoteIpHeader()).isEqualTo("Remote-Ip"); assertThat(tomcat.getRemoteIpHeader()).isEqualTo("Remote-Ip");
assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol"); assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol");
assertThat(tomcat.getInternalProxies()).isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); assertThat(tomcat.getInternalProxies()).isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
assertThat(tomcat.getBackgroundProcessorDelay()).isEqualTo(Duration.ofSeconds(10)); assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10);
assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<'); assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<');
assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|'); assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|');
} }
...@@ -235,7 +234,7 @@ class ServerPropertiesTests { ...@@ -235,7 +234,7 @@ class ServerPropertiesTests {
@Test @Test
void testCustomizeJettyIdleTimeout() { void testCustomizeJettyIdleTimeout() {
bind("server.jetty.thread-idle-timeout", "10s"); bind("server.jetty.thread-idle-timeout", "10s");
assertThat(this.properties.getJetty().getThreadIdleTimeout()).isEqualTo(Duration.ofSeconds(10)); assertThat(this.properties.getJetty().getThreadIdleTimeout()).hasSeconds(10);
} }
@Test @Test
...@@ -308,7 +307,7 @@ class ServerPropertiesTests { ...@@ -308,7 +307,7 @@ class ServerPropertiesTests {
@Test @Test
void tomcatBackgroundProcessorDelayMatchesEngineDefault() { void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
assertThat(this.properties.getTomcat().getBackgroundProcessorDelay()) assertThat(this.properties.getTomcat().getBackgroundProcessorDelay())
.isEqualTo(Duration.ofSeconds((new StandardEngine().getBackgroundProcessorDelay()))); .hasSeconds((new StandardEngine().getBackgroundProcessorDelay()));
} }
@Test @Test
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.web.servlet; package org.springframework.boot.autoconfigure.web.servlet;
import java.io.File; import java.io.File;
import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -106,14 +105,14 @@ class ServletWebServerFactoryCustomizerTests { ...@@ -106,14 +105,14 @@ class ServletWebServerFactoryCustomizerTests {
this.customizer.customize(factory); this.customizer.customize(factory);
ArgumentCaptor<Session> sessionCaptor = ArgumentCaptor.forClass(Session.class); ArgumentCaptor<Session> sessionCaptor = ArgumentCaptor.forClass(Session.class);
verify(factory).setSession(sessionCaptor.capture()); verify(factory).setSession(sessionCaptor.capture());
assertThat(sessionCaptor.getValue().getTimeout()).isEqualTo(Duration.ofSeconds(123)); assertThat(sessionCaptor.getValue().getTimeout()).hasSeconds(123);
Cookie cookie = sessionCaptor.getValue().getCookie(); Cookie cookie = sessionCaptor.getValue().getCookie();
assertThat(cookie.getName()).isEqualTo("testname"); assertThat(cookie.getName()).isEqualTo("testname");
assertThat(cookie.getDomain()).isEqualTo("testdomain"); assertThat(cookie.getDomain()).isEqualTo("testdomain");
assertThat(cookie.getPath()).isEqualTo("/testpath"); assertThat(cookie.getPath()).isEqualTo("/testpath");
assertThat(cookie.getComment()).isEqualTo("testcomment"); assertThat(cookie.getComment()).isEqualTo("testcomment");
assertThat(cookie.getHttpOnly()).isTrue(); assertThat(cookie.getHttpOnly()).isTrue();
assertThat(cookie.getMaxAge()).isEqualTo(Duration.ofSeconds(60)); assertThat(cookie.getMaxAge()).hasSeconds(60);
} }
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package org.springframework.boot.devtools.autoconfigure; package org.springframework.boot.devtools.autoconfigure;
import java.io.File; import java.io.File;
import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -115,7 +114,7 @@ class LocalDevToolsAutoConfigurationTests { ...@@ -115,7 +114,7 @@ class LocalDevToolsAutoConfigurationTests {
void resourceCachePeriodIsZero() throws Exception { void resourceCachePeriodIsZero() throws Exception {
this.context = getContext(() -> initializeAndRun(WebResourcesConfig.class)); this.context = getContext(() -> initializeAndRun(WebResourcesConfig.class));
ResourceProperties properties = this.context.getBean(ResourceProperties.class); ResourceProperties properties = this.context.getBean(ResourceProperties.class);
assertThat(properties.getCache().getPeriod()).isEqualTo(Duration.ZERO); assertThat(properties.getCache().getPeriod()).isZero();
} }
@Test @Test
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.boot.docs.context.properties.bind; package org.springframework.boot.docs.context.properties.bind;
import java.time.Duration;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -43,8 +42,8 @@ class AppSystemPropertiesTests { ...@@ -43,8 +42,8 @@ class AppSystemPropertiesTests {
void bindWithDefaultUnit() { void bindWithDefaultUnit() {
this.contextRunner.withPropertyValues("app.system.session-timeout=40", "app.system.read-timeout=5000") this.contextRunner.withPropertyValues("app.system.session-timeout=40", "app.system.read-timeout=5000")
.run(assertBinding((properties) -> { .run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(40)); assertThat(properties.getSessionTimeout()).hasSeconds(40);
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000)); assertThat(properties.getReadTimeout()).hasMillis(5000);
})); }));
} }
...@@ -52,8 +51,8 @@ class AppSystemPropertiesTests { ...@@ -52,8 +51,8 @@ class AppSystemPropertiesTests {
void bindWithExplicitUnit() { void bindWithExplicitUnit() {
this.contextRunner.withPropertyValues("app.system.session-timeout=1h", "app.system.read-timeout=5s") this.contextRunner.withPropertyValues("app.system.session-timeout=1h", "app.system.read-timeout=5s")
.run(assertBinding((properties) -> { .run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofMinutes(60)); assertThat(properties.getSessionTimeout()).hasMinutes(60);
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000)); assertThat(properties.getReadTimeout()).hasMillis(5000);
})); }));
} }
...@@ -61,8 +60,8 @@ class AppSystemPropertiesTests { ...@@ -61,8 +60,8 @@ class AppSystemPropertiesTests {
void bindWithIso8601Format() { void bindWithIso8601Format() {
this.contextRunner.withPropertyValues("app.system.session-timeout=PT15S", "app.system.read-timeout=PT0.5S") this.contextRunner.withPropertyValues("app.system.session-timeout=PT15S", "app.system.read-timeout=PT0.5S")
.run(assertBinding((properties) -> { .run(assertBinding((properties) -> {
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(15)); assertThat(properties.getSessionTimeout()).hasSeconds(15);
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(500)); assertThat(properties.getReadTimeout()).hasMillis(500);
})); }));
} }
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package org.springframework.boot.test.autoconfigure.web.reactive; package org.springframework.boot.test.autoconfigure.web.reactive;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -75,8 +74,8 @@ class WebTestClientAutoConfigurationTests { ...@@ -75,8 +74,8 @@ class WebTestClientAutoConfigurationTests {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("spring.test.webtestclient.timeout=15m").run((context) -> { .withPropertyValues("spring.test.webtestclient.timeout=15m").run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class); WebTestClient webTestClient = context.getBean(WebTestClient.class);
Object duration = ReflectionTestUtils.getField(webTestClient, "timeout"); Duration duration = (Duration) ReflectionTestUtils.getField(webTestClient, "timeout");
assertThat(duration).isEqualTo(Duration.of(15, ChronoUnit.MINUTES)); assertThat(duration).hasMinutes(15);
}); });
} }
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,72 +51,72 @@ class DurationStyleTests { ...@@ -51,72 +51,72 @@ class DurationStyleTests {
@Test @Test
void detectAndParseWhenSimpleNanosShouldReturnDuration() { void detectAndParseWhenSimpleNanosShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10ns")).isEqualTo(Duration.ofNanos(10)); assertThat(DurationStyle.detectAndParse("10ns")).hasNanos(10);
assertThat(DurationStyle.detectAndParse("10NS")).isEqualTo(Duration.ofNanos(10)); assertThat(DurationStyle.detectAndParse("10NS")).hasNanos(10);
assertThat(DurationStyle.detectAndParse("+10ns")).isEqualTo(Duration.ofNanos(10)); assertThat(DurationStyle.detectAndParse("+10ns")).hasNanos(10);
assertThat(DurationStyle.detectAndParse("-10ns")).isEqualTo(Duration.ofNanos(-10)); assertThat(DurationStyle.detectAndParse("-10ns")).hasNanos(-10);
} }
@Test @Test
void detectAndParseWhenSimpleMicrosShouldReturnDuration() { void detectAndParseWhenSimpleMicrosShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10us")).isEqualTo(Duration.ofNanos(10000)); assertThat(DurationStyle.detectAndParse("10us")).hasNanos(10000);
assertThat(DurationStyle.detectAndParse("10US")).isEqualTo(Duration.ofNanos(10000)); assertThat(DurationStyle.detectAndParse("10US")).hasNanos(10000);
assertThat(DurationStyle.detectAndParse("+10us")).isEqualTo(Duration.ofNanos(10000)); assertThat(DurationStyle.detectAndParse("+10us")).hasNanos(10000);
assertThat(DurationStyle.detectAndParse("-10us")).isEqualTo(Duration.ofNanos(-10000)); assertThat(DurationStyle.detectAndParse("-10us")).hasNanos(-10000);
} }
@Test @Test
void detectAndParseWhenSimpleMillisShouldReturnDuration() { void detectAndParseWhenSimpleMillisShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10ms")).isEqualTo(Duration.ofMillis(10)); assertThat(DurationStyle.detectAndParse("10ms")).hasMillis(10);
assertThat(DurationStyle.detectAndParse("10MS")).isEqualTo(Duration.ofMillis(10)); assertThat(DurationStyle.detectAndParse("10MS")).hasMillis(10);
assertThat(DurationStyle.detectAndParse("+10ms")).isEqualTo(Duration.ofMillis(10)); assertThat(DurationStyle.detectAndParse("+10ms")).hasMillis(10);
assertThat(DurationStyle.detectAndParse("-10ms")).isEqualTo(Duration.ofMillis(-10)); assertThat(DurationStyle.detectAndParse("-10ms")).hasMillis(-10);
} }
@Test @Test
void detectAndParseWhenSimpleSecondsShouldReturnDuration() { void detectAndParseWhenSimpleSecondsShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10s")).isEqualTo(Duration.ofSeconds(10)); assertThat(DurationStyle.detectAndParse("10s")).hasSeconds(10);
assertThat(DurationStyle.detectAndParse("10S")).isEqualTo(Duration.ofSeconds(10)); assertThat(DurationStyle.detectAndParse("10S")).hasSeconds(10);
assertThat(DurationStyle.detectAndParse("+10s")).isEqualTo(Duration.ofSeconds(10)); assertThat(DurationStyle.detectAndParse("+10s")).hasSeconds(10);
assertThat(DurationStyle.detectAndParse("-10s")).isEqualTo(Duration.ofSeconds(-10)); assertThat(DurationStyle.detectAndParse("-10s")).hasSeconds(-10);
} }
@Test @Test
void detectAndParseWhenSimpleMinutesShouldReturnDuration() { void detectAndParseWhenSimpleMinutesShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10m")).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.detectAndParse("10m")).hasMinutes(10);
assertThat(DurationStyle.detectAndParse("10M")).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.detectAndParse("10M")).hasMinutes(10);
assertThat(DurationStyle.detectAndParse("+10m")).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.detectAndParse("+10m")).hasMinutes(10);
assertThat(DurationStyle.detectAndParse("-10m")).isEqualTo(Duration.ofMinutes(-10)); assertThat(DurationStyle.detectAndParse("-10m")).hasMinutes(-10);
} }
@Test @Test
void detectAndParseWhenSimpleHoursShouldReturnDuration() { void detectAndParseWhenSimpleHoursShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10h")).isEqualTo(Duration.ofHours(10)); assertThat(DurationStyle.detectAndParse("10h")).hasHours(10);
assertThat(DurationStyle.detectAndParse("10H")).isEqualTo(Duration.ofHours(10)); assertThat(DurationStyle.detectAndParse("10H")).hasHours(10);
assertThat(DurationStyle.detectAndParse("+10h")).isEqualTo(Duration.ofHours(10)); assertThat(DurationStyle.detectAndParse("+10h")).hasHours(10);
assertThat(DurationStyle.detectAndParse("-10h")).isEqualTo(Duration.ofHours(-10)); assertThat(DurationStyle.detectAndParse("-10h")).hasHours(-10);
} }
@Test @Test
void detectAndParseWhenSimpleDaysShouldReturnDuration() { void detectAndParseWhenSimpleDaysShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10d")).isEqualTo(Duration.ofDays(10)); assertThat(DurationStyle.detectAndParse("10d")).hasDays(10);
assertThat(DurationStyle.detectAndParse("10D")).isEqualTo(Duration.ofDays(10)); assertThat(DurationStyle.detectAndParse("10D")).hasDays(10);
assertThat(DurationStyle.detectAndParse("+10d")).isEqualTo(Duration.ofDays(10)); assertThat(DurationStyle.detectAndParse("+10d")).hasDays(10);
assertThat(DurationStyle.detectAndParse("-10d")).isEqualTo(Duration.ofDays(-10)); assertThat(DurationStyle.detectAndParse("-10d")).hasDays(-10);
} }
@Test @Test
void detectAndParseWhenSimpleWithoutSuffixShouldReturnDuration() { void detectAndParseWhenSimpleWithoutSuffixShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10")).isEqualTo(Duration.ofMillis(10)); assertThat(DurationStyle.detectAndParse("10")).hasMillis(10);
assertThat(DurationStyle.detectAndParse("+10")).isEqualTo(Duration.ofMillis(10)); assertThat(DurationStyle.detectAndParse("+10")).hasMillis(10);
assertThat(DurationStyle.detectAndParse("-10")).isEqualTo(Duration.ofMillis(-10)); assertThat(DurationStyle.detectAndParse("-10")).hasMillis(-10);
} }
@Test @Test
void detectAndParseWhenSimpleWithoutSuffixButWithChronoUnitShouldReturnDuration() { void detectAndParseWhenSimpleWithoutSuffixButWithChronoUnitShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); assertThat(DurationStyle.detectAndParse("10", ChronoUnit.SECONDS)).hasSeconds(10);
assertThat(DurationStyle.detectAndParse("+10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); assertThat(DurationStyle.detectAndParse("+10", ChronoUnit.SECONDS)).hasSeconds(10);
assertThat(DurationStyle.detectAndParse("-10", ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(-10)); assertThat(DurationStyle.detectAndParse("-10", ChronoUnit.SECONDS)).hasSeconds(-10);
} }
@Test @Test
...@@ -191,13 +191,13 @@ class DurationStyleTests { ...@@ -191,13 +191,13 @@ class DurationStyleTests {
@Test @Test
void parseSimpleShouldParse() { void parseSimpleShouldParse() {
assertThat(DurationStyle.SIMPLE.parse("10m")).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.SIMPLE.parse("10m")).hasMinutes(10);
} }
@Test @Test
void parseSimpleWithUnitShouldUseUnitAsFallback() { void parseSimpleWithUnitShouldUseUnitAsFallback() {
assertThat(DurationStyle.SIMPLE.parse("10m", ChronoUnit.SECONDS)).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.SIMPLE.parse("10m", ChronoUnit.SECONDS)).hasMinutes(10);
assertThat(DurationStyle.SIMPLE.parse("10", ChronoUnit.MINUTES)).isEqualTo(Duration.ofMinutes(10)); assertThat(DurationStyle.SIMPLE.parse("10", ChronoUnit.MINUTES)).hasMinutes(10);
} }
@Test @Test
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -40,16 +40,16 @@ class NumberToDurationConverterTests { ...@@ -40,16 +40,16 @@ class NumberToDurationConverterTests {
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleWithoutSuffixShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleWithoutSuffixShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, 10)).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, 10)).hasMillis(10);
assertThat(convert(conversionService, +10)).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, +10)).hasMillis(10);
assertThat(convert(conversionService, -10)).isEqualTo(Duration.ofMillis(-10)); assertThat(convert(conversionService, -10)).hasMillis(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleWithoutSuffixButWithAnnotationShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleWithoutSuffixButWithAnnotationShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, 10, ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, 10, ChronoUnit.SECONDS)).hasSeconds(10);
assertThat(convert(conversionService, +10, ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, +10, ChronoUnit.SECONDS)).hasSeconds(10);
assertThat(convert(conversionService, -10, ChronoUnit.SECONDS)).isEqualTo(Duration.ofSeconds(-10)); assertThat(convert(conversionService, -10, ChronoUnit.SECONDS)).hasSeconds(-10);
} }
private Duration convert(ConversionService conversionService, Integer source) { private Duration convert(ConversionService conversionService, Integer source) {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -50,72 +50,72 @@ class StringToDurationConverterTests { ...@@ -50,72 +50,72 @@ class StringToDurationConverterTests {
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleNanosShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleNanosShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10ns")).isEqualTo(Duration.ofNanos(10)); assertThat(convert(conversionService, "10ns")).hasNanos(10);
assertThat(convert(conversionService, "10NS")).isEqualTo(Duration.ofNanos(10)); assertThat(convert(conversionService, "10NS")).hasNanos(10);
assertThat(convert(conversionService, "+10ns")).isEqualTo(Duration.ofNanos(10)); assertThat(convert(conversionService, "+10ns")).hasNanos(10);
assertThat(convert(conversionService, "-10ns")).isEqualTo(Duration.ofNanos(-10)); assertThat(convert(conversionService, "-10ns")).hasNanos(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleMicrosShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleMicrosShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10us")).isEqualTo(Duration.ofNanos(10000)); assertThat(convert(conversionService, "10us")).hasNanos(10000);
assertThat(convert(conversionService, "10US")).isEqualTo(Duration.ofNanos(10000)); assertThat(convert(conversionService, "10US")).hasNanos(10000);
assertThat(convert(conversionService, "+10us")).isEqualTo(Duration.ofNanos(10000)); assertThat(convert(conversionService, "+10us")).hasNanos(10000);
assertThat(convert(conversionService, "-10us")).isEqualTo(Duration.ofNanos(-10000)); assertThat(convert(conversionService, "-10us")).hasNanos(-10000);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleMillisShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleMillisShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10ms")).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, "10ms")).hasMillis(10);
assertThat(convert(conversionService, "10MS")).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, "10MS")).hasMillis(10);
assertThat(convert(conversionService, "+10ms")).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, "+10ms")).hasMillis(10);
assertThat(convert(conversionService, "-10ms")).isEqualTo(Duration.ofMillis(-10)); assertThat(convert(conversionService, "-10ms")).hasMillis(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleSecondsShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleSecondsShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10s")).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, "10s")).hasSeconds(10);
assertThat(convert(conversionService, "10S")).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, "10S")).hasSeconds(10);
assertThat(convert(conversionService, "+10s")).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, "+10s")).hasSeconds(10);
assertThat(convert(conversionService, "-10s")).isEqualTo(Duration.ofSeconds(-10)); assertThat(convert(conversionService, "-10s")).hasSeconds(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleMinutesShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleMinutesShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10m")).isEqualTo(Duration.ofMinutes(10)); assertThat(convert(conversionService, "10m")).hasMinutes(10);
assertThat(convert(conversionService, "10M")).isEqualTo(Duration.ofMinutes(10)); assertThat(convert(conversionService, "10M")).hasMinutes(10);
assertThat(convert(conversionService, "+10m")).isEqualTo(Duration.ofMinutes(10)); assertThat(convert(conversionService, "+10m")).hasMinutes(10);
assertThat(convert(conversionService, "-10m")).isEqualTo(Duration.ofMinutes(-10)); assertThat(convert(conversionService, "-10m")).hasMinutes(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleHoursShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleHoursShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10h")).isEqualTo(Duration.ofHours(10)); assertThat(convert(conversionService, "10h")).hasHours(10);
assertThat(convert(conversionService, "10H")).isEqualTo(Duration.ofHours(10)); assertThat(convert(conversionService, "10H")).hasHours(10);
assertThat(convert(conversionService, "+10h")).isEqualTo(Duration.ofHours(10)); assertThat(convert(conversionService, "+10h")).hasHours(10);
assertThat(convert(conversionService, "-10h")).isEqualTo(Duration.ofHours(-10)); assertThat(convert(conversionService, "-10h")).hasHours(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleDaysShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleDaysShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10d")).isEqualTo(Duration.ofDays(10)); assertThat(convert(conversionService, "10d")).hasDays(10);
assertThat(convert(conversionService, "10D")).isEqualTo(Duration.ofDays(10)); assertThat(convert(conversionService, "10D")).hasDays(10);
assertThat(convert(conversionService, "+10d")).isEqualTo(Duration.ofDays(10)); assertThat(convert(conversionService, "+10d")).hasDays(10);
assertThat(convert(conversionService, "-10d")).isEqualTo(Duration.ofDays(-10)); assertThat(convert(conversionService, "-10d")).hasDays(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleWithoutSuffixShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleWithoutSuffixShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10")).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, "10")).hasMillis(10);
assertThat(convert(conversionService, "+10")).isEqualTo(Duration.ofMillis(10)); assertThat(convert(conversionService, "+10")).hasMillis(10);
assertThat(convert(conversionService, "-10")).isEqualTo(Duration.ofMillis(-10)); assertThat(convert(conversionService, "-10")).hasMillis(-10);
} }
@ConversionServiceTest @ConversionServiceTest
void convertWhenSimpleWithoutSuffixButWithAnnotationShouldReturnDuration(ConversionService conversionService) { void convertWhenSimpleWithoutSuffixButWithAnnotationShouldReturnDuration(ConversionService conversionService) {
assertThat(convert(conversionService, "10", ChronoUnit.SECONDS, null)).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, "10", ChronoUnit.SECONDS, null)).hasSeconds(10);
assertThat(convert(conversionService, "+10", ChronoUnit.SECONDS, null)).isEqualTo(Duration.ofSeconds(10)); assertThat(convert(conversionService, "+10", ChronoUnit.SECONDS, null)).hasSeconds(10);
assertThat(convert(conversionService, "-10", ChronoUnit.SECONDS, null)).isEqualTo(Duration.ofSeconds(-10)); assertThat(convert(conversionService, "-10", ChronoUnit.SECONDS, null)).hasSeconds(-10);
} }
@ConversionServiceTest @ConversionServiceTest
......
...@@ -676,7 +676,7 @@ public abstract class AbstractServletWebServerFactoryTests { ...@@ -676,7 +676,7 @@ public abstract class AbstractServletWebServerFactoryTests {
@Test @Test
void defaultSessionTimeout() { void defaultSessionTimeout() {
assertThat(getFactory().getSession().getTimeout()).isEqualTo(Duration.ofMinutes(30)); assertThat(getFactory().getSession().getTimeout()).hasMinutes(30);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment