Use new AssertJ duration assertions

See gh-19985
This commit is contained in:
dreis2211
2020-01-30 08:02:22 +01:00
committed by Stephane Nicoll
parent 7de3712e56
commit fac6f08ca3
12 changed files with 108 additions and 116 deletions

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ class JmsPropertiesTests {
@Test
void defaultReceiveTimeoutMatchesListenerContainersDefault() {
assertThat(new JmsProperties().getListener().getReceiveTimeout())
.isEqualTo(Duration.ofMillis(AbstractPollingMessageListenerContainer.DEFAULT_RECEIVE_TIMEOUT));
.hasMillis(AbstractPollingMessageListenerContainer.DEFAULT_RECEIVE_TIMEOUT);
}
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.session;
import java.time.Duration;
import java.util.Collections;
import java.util.EnumSet;
@@ -98,8 +97,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=1", "spring.session.timeout=3")
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3)));
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()).hasSeconds(3));
}
@Test
@@ -107,8 +105,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class, SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=3")
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3)));
.run((context) -> assertThat(context.getBean(SessionProperties.class).getTimeout()).hasSeconds(3));
}
@SuppressWarnings("unchecked")

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -107,7 +106,7 @@ class ServerPropertiesTests {
@Test
void testConnectionTimeout() {
bind("server.connection-timeout", "60s");
assertThat(this.properties.getConnectionTimeout()).isEqualTo(Duration.ofMillis(60000));
assertThat(this.properties.getConnectionTimeout()).hasMillis(60000);
}
@Test
@@ -149,7 +148,7 @@ class ServerPropertiesTests {
assertThat(tomcat.getRemoteIpHeader()).isEqualTo("Remote-Ip");
assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol");
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.getRelaxedQueryChars()).containsExactly('^', '|');
}
@@ -235,7 +234,7 @@ class ServerPropertiesTests {
@Test
void testCustomizeJettyIdleTimeout() {
bind("server.jetty.thread-idle-timeout", "10s");
assertThat(this.properties.getJetty().getThreadIdleTimeout()).isEqualTo(Duration.ofSeconds(10));
assertThat(this.properties.getJetty().getThreadIdleTimeout()).hasSeconds(10);
}
@Test
@@ -308,7 +307,7 @@ class ServerPropertiesTests {
@Test
void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
assertThat(this.properties.getTomcat().getBackgroundProcessorDelay())
.isEqualTo(Duration.ofSeconds((new StandardEngine().getBackgroundProcessorDelay())));
.hasSeconds((new StandardEngine().getBackgroundProcessorDelay()));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.web.servlet;
import java.io.File;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
@@ -106,14 +105,14 @@ class ServletWebServerFactoryCustomizerTests {
this.customizer.customize(factory);
ArgumentCaptor<Session> sessionCaptor = ArgumentCaptor.forClass(Session.class);
verify(factory).setSession(sessionCaptor.capture());
assertThat(sessionCaptor.getValue().getTimeout()).isEqualTo(Duration.ofSeconds(123));
assertThat(sessionCaptor.getValue().getTimeout()).hasSeconds(123);
Cookie cookie = sessionCaptor.getValue().getCookie();
assertThat(cookie.getName()).isEqualTo("testname");
assertThat(cookie.getDomain()).isEqualTo("testdomain");
assertThat(cookie.getPath()).isEqualTo("/testpath");
assertThat(cookie.getComment()).isEqualTo("testcomment");
assertThat(cookie.getHttpOnly()).isTrue();
assertThat(cookie.getMaxAge()).isEqualTo(Duration.ofSeconds(60));
assertThat(cookie.getMaxAge()).hasSeconds(60);
}