Browse Source

Polish tests

See gh-25456
pull/25461/head
Sam Brannen 5 years ago
parent
commit
ae5913f3b6
  1. 12
      spring-aspects/src/test/java/org/springframework/cache/aspectj/AbstractCacheAnnotationTests.java
  2. 12
      spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/AbstractCacheAnnotationTests.java
  3. 61
      spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java

12
spring-aspects/src/test/java/org/springframework/cache/aspectj/AbstractCacheAnnotationTests.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-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.
@ -412,15 +412,15 @@ public abstract class AbstractCacheAnnotationTests {
} }
protected void testConditionalCacheUpdate(CacheableService<?> service) { protected void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = 1; int one = 1;
Integer three = 3; int three = 3;
Cache cache = this.cm.getCache("testCache"); Cache cache = this.cm.getCache("testCache");
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one); assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
assertThat(cache.get(one)).isNull(); assertThat(cache.get(one)).isNull();
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three); assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three); assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
} }
protected void testMultiCache(CacheableService<?> service) { protected void testMultiCache(CacheableService<?> service) {

12
spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/AbstractCacheAnnotationTests.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-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.
@ -407,15 +407,15 @@ public abstract class AbstractCacheAnnotationTests {
} }
protected void testConditionalCacheUpdate(CacheableService<?> service) { protected void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = 1; int one = 1;
Integer three = 3; int three = 3;
Cache cache = this.cm.getCache("testCache"); Cache cache = this.cm.getCache("testCache");
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one); assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
assertThat(cache.get(one)).isNull(); assertThat(cache.get(one)).isNull();
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three); assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three); assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
} }
protected void testMultiCache(CacheableService<?> service) { protected void testMultiCache(CacheableService<?> service) {

61
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-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.
@ -19,6 +19,8 @@ package org.springframework.web.socket.sockjs.client;
import java.net.URI; import java.net.URI;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.web.socket.sockjs.transport.TransportType; import org.springframework.web.socket.sockjs.transport.TransportType;
@ -28,52 +30,47 @@ import static org.assertj.core.api.Assertions.assertThat;
* Unit tests for {@code SockJsUrlInfo}. * Unit tests for {@code SockJsUrlInfo}.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen
*/ */
public class SockJsUrlInfoTests { class SockJsUrlInfoTests {
@Test @Test
public void serverId() throws Exception { void serverId() throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
int serverId = Integer.parseInt(info.getServerId()); int serverId = Integer.parseInt(info.getServerId());
assertThat(serverId >= 0 && serverId < 1000).as("Invalid serverId: " + serverId).isTrue(); assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000);
} }
@Test @Test
public void sessionId() throws Exception { void sessionId() throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
assertThat(info.getSessionId().length()).as("Invalid sessionId: " + info.getSessionId()).isEqualTo(32); assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32);
} }
@Test @ParameterizedTest
public void infoUrl() throws Exception { @CsvSource( {
testInfoUrl("http", "http"); "http, http",
testInfoUrl("http", "http"); "https, https",
testInfoUrl("https", "https"); "ws, http",
testInfoUrl("https", "https"); "wss, https",
testInfoUrl("ws", "http"); })
testInfoUrl("ws", "http"); void infoUrl(String scheme, String expectedScheme) throws Exception {
testInfoUrl("wss", "https");
testInfoUrl("wss", "https");
}
private void testInfoUrl(String scheme, String expectedScheme) throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info")); assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
} }
@Test @ParameterizedTest
public void transportUrl() throws Exception { @CsvSource( {
testTransportUrl("http", "http", TransportType.XHR_STREAMING); "http, http, XHR_STREAMING",
testTransportUrl("http", "ws", TransportType.WEBSOCKET); "http, ws, WEBSOCKET",
testTransportUrl("https", "https", TransportType.XHR_STREAMING); "https, https, XHR_STREAMING",
testTransportUrl("https", "wss", TransportType.WEBSOCKET); "https, wss, WEBSOCKET",
testTransportUrl("ws", "http", TransportType.XHR_STREAMING); "ws, http, XHR_STREAMING",
testTransportUrl("ws", "ws", TransportType.WEBSOCKET); "ws, ws, WEBSOCKET",
testTransportUrl("wss", "https", TransportType.XHR_STREAMING); "wss, https, XHR_STREAMING",
testTransportUrl("wss", "wss", TransportType.WEBSOCKET); "wss, wss, WEBSOCKET"
} })
void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
String serverId = info.getServerId(); String serverId = info.getServerId();
String sessionId = info.getSessionId(); String sessionId = info.getSessionId();

Loading…
Cancel
Save