Skip to content

Commit ae5913f

Browse files
committed
Polish tests
See gh-25456
1 parent cd12583 commit ae5913f

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -412,15 +412,15 @@ protected void testCacheUpdate(CacheableService<?> service) {
412412
}
413413

414414
protected void testConditionalCacheUpdate(CacheableService<?> service) {
415-
Integer one = 1;
416-
Integer three = 3;
415+
int one = 1;
416+
int three = 3;
417417

418418
Cache cache = this.cm.getCache("testCache");
419-
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
419+
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
420420
assertThat(cache.get(one)).isNull();
421421

422-
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
423-
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three);
422+
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
423+
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
424424
}
425425

426426
protected void testMultiCache(CacheableService<?> service) {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -407,15 +407,15 @@ protected void testCacheUpdate(CacheableService<?> service) {
407407
}
408408

409409
protected void testConditionalCacheUpdate(CacheableService<?> service) {
410-
Integer one = 1;
411-
Integer three = 3;
410+
int one = 1;
411+
int three = 3;
412412

413413
Cache cache = this.cm.getCache("testCache");
414-
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
414+
assertThat(Integer.parseInt(service.conditionalUpdate(one).toString())).isEqualTo(one);
415415
assertThat(cache.get(one)).isNull();
416416

417-
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
418-
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo((int) three);
417+
assertThat(Integer.parseInt(service.conditionalUpdate(three).toString())).isEqualTo(three);
418+
assertThat(Integer.parseInt(cache.get(three).get().toString())).isEqualTo(three);
419419
}
420420

421421
protected void testMultiCache(CacheableService<?> service) {

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

+29-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
import java.net.URI;
2020

2121
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.CsvSource;
2224

2325
import org.springframework.web.socket.sockjs.transport.TransportType;
2426

@@ -28,52 +30,47 @@
2830
* Unit tests for {@code SockJsUrlInfo}.
2931
*
3032
* @author Rossen Stoyanchev
33+
* @author Sam Brannen
3134
*/
32-
public class SockJsUrlInfoTests {
35+
class SockJsUrlInfoTests {
3336

3437
@Test
35-
public void serverId() throws Exception {
38+
void serverId() throws Exception {
3639
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
3740
int serverId = Integer.parseInt(info.getServerId());
38-
assertThat(serverId >= 0 && serverId < 1000).as("Invalid serverId: " + serverId).isTrue();
41+
assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000);
3942
}
4043

4144
@Test
42-
public void sessionId() throws Exception {
45+
void sessionId() throws Exception {
4346
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
44-
assertThat(info.getSessionId().length()).as("Invalid sessionId: " + info.getSessionId()).isEqualTo(32);
47+
assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32);
4548
}
4649

47-
@Test
48-
public void infoUrl() throws Exception {
49-
testInfoUrl("http", "http");
50-
testInfoUrl("http", "http");
51-
testInfoUrl("https", "https");
52-
testInfoUrl("https", "https");
53-
testInfoUrl("ws", "http");
54-
testInfoUrl("ws", "http");
55-
testInfoUrl("wss", "https");
56-
testInfoUrl("wss", "https");
57-
}
58-
59-
private void testInfoUrl(String scheme, String expectedScheme) throws Exception {
50+
@ParameterizedTest
51+
@CsvSource( {
52+
"http, http",
53+
"https, https",
54+
"ws, http",
55+
"wss, https",
56+
})
57+
void infoUrl(String scheme, String expectedScheme) throws Exception {
6058
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
6159
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
6260
}
6361

64-
@Test
65-
public void transportUrl() throws Exception {
66-
testTransportUrl("http", "http", TransportType.XHR_STREAMING);
67-
testTransportUrl("http", "ws", TransportType.WEBSOCKET);
68-
testTransportUrl("https", "https", TransportType.XHR_STREAMING);
69-
testTransportUrl("https", "wss", TransportType.WEBSOCKET);
70-
testTransportUrl("ws", "http", TransportType.XHR_STREAMING);
71-
testTransportUrl("ws", "ws", TransportType.WEBSOCKET);
72-
testTransportUrl("wss", "https", TransportType.XHR_STREAMING);
73-
testTransportUrl("wss", "wss", TransportType.WEBSOCKET);
74-
}
75-
76-
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
62+
@ParameterizedTest
63+
@CsvSource( {
64+
"http, http, XHR_STREAMING",
65+
"http, ws, WEBSOCKET",
66+
"https, https, XHR_STREAMING",
67+
"https, wss, WEBSOCKET",
68+
"ws, http, XHR_STREAMING",
69+
"ws, ws, WEBSOCKET",
70+
"wss, https, XHR_STREAMING",
71+
"wss, wss, WEBSOCKET"
72+
})
73+
void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
7774
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
7875
String serverId = info.getServerId();
7976
String sessionId = info.getSessionId();

0 commit comments

Comments
 (0)