Refactor AssertJ assertions into more idiomatic ones

This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
This commit is contained in:
Krzysztof Krasoń
2023-04-04 17:34:07 +02:00
committed by GitHub
parent dd97ee4e99
commit 1734deca1e
371 changed files with 3177 additions and 3076 deletions

View File

@@ -554,7 +554,7 @@ public class HttpHeadersTests {
headers.setBasicAuth(username, password);
String authorization = headers.getFirst(HttpHeaders.AUTHORIZATION);
assertThat(authorization).isNotNull();
assertThat(authorization.startsWith("Basic ")).isTrue();
assertThat(authorization).startsWith("Basic ");
byte[] result = Base64.getDecoder().decode(authorization.substring(6).getBytes(StandardCharsets.ISO_8859_1));
assertThat(new String(result, StandardCharsets.ISO_8859_1)).isEqualTo("foo:bar");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -29,16 +29,16 @@ public class MediaTypeFactoryTests {
@Test
public void getMediaType() {
assertThat(MediaTypeFactory.getMediaType("file.xml").get()).isEqualTo(MediaType.APPLICATION_XML);
assertThat(MediaTypeFactory.getMediaType("file.js").get()).isEqualTo(MediaType.parseMediaType("application/javascript"));
assertThat(MediaTypeFactory.getMediaType("file.css").get()).isEqualTo(MediaType.parseMediaType("text/css"));
assertThat(MediaTypeFactory.getMediaType("file.foobar").isPresent()).isFalse();
assertThat(MediaTypeFactory.getMediaType("file.xml")).contains(MediaType.APPLICATION_XML);
assertThat(MediaTypeFactory.getMediaType("file.js")).contains(MediaType.parseMediaType("application/javascript"));
assertThat(MediaTypeFactory.getMediaType("file.css")).contains(MediaType.parseMediaType("text/css"));
assertThat(MediaTypeFactory.getMediaType("file.foobar")).isNotPresent();
}
@Test
public void nullParameter() {
assertThat(MediaTypeFactory.getMediaType((String) null).isPresent()).isFalse();
assertThat(MediaTypeFactory.getMediaType((Resource) null).isPresent()).isFalse();
assertThat(MediaTypeFactory.getMediaType((String) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaType((Resource) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaTypes(null).isEmpty()).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -156,18 +156,18 @@ public class MediaTypeTests {
String s = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
List<MediaType> mediaTypes = MediaType.parseMediaTypes(s);
assertThat(mediaTypes).as("No media types returned").isNotNull();
assertThat(mediaTypes.size()).as("Invalid amount of media types").isEqualTo(4);
assertThat(mediaTypes).as("Invalid amount of media types").hasSize(4);
mediaTypes = MediaType.parseMediaTypes("");
assertThat(mediaTypes).as("No media types returned").isNotNull();
assertThat(mediaTypes.size()).as("Invalid amount of media types").isEqualTo(0);
assertThat(mediaTypes).as("Invalid amount of media types").isEmpty();
}
@Test // gh-23241
public void parseMediaTypesWithTrailingComma() {
List<MediaType> mediaTypes = MediaType.parseMediaTypes("text/plain, text/html, ");
assertThat(mediaTypes).as("No media types returned").isNotNull();
assertThat(mediaTypes.size()).as("Incorrect number of media types").isEqualTo(2);
assertThat(mediaTypes).as("Incorrect number of media types").hasSize(2);
}
@Test
@@ -183,7 +183,7 @@ public class MediaTypeTests {
assertThat(audio.compareTo(audio)).as("Invalid comparison result").isEqualTo(0);
assertThat(audioBasicLevel.compareTo(audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
assertThat(audioBasicLevel.compareTo(audio) > 0).as("Invalid comparison result").isTrue();
assertThat(audioBasicLevel.compareTo(audio)).as("Invalid comparison result").isGreaterThan(0);
List<MediaType> expected = new ArrayList<>();
expected.add(audio);
@@ -235,8 +235,8 @@ public class MediaTypeTests {
m1 = new MediaType("audio", "basic", Collections.singletonMap("foo", "bar"));
m2 = new MediaType("audio", "basic", Collections.singletonMap("foo", "Bar"));
assertThat(m1.compareTo(m2) != 0).as("Invalid comparison result").isTrue();
assertThat(m2.compareTo(m1) != 0).as("Invalid comparison result").isTrue();
assertThat(m1.compareTo(m2)).as("Invalid comparison result").isNotEqualTo(0);
assertThat(m2.compareTo(m1)).as("Invalid comparison result").isNotEqualTo(0);
}
@@ -302,28 +302,29 @@ public class MediaTypeTests {
assertThat(comp.compare(audioBasicLevel, audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
// specific to unspecific
assertThat(comp.compare(audioBasic, audio) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, all) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, all) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, audio)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audioBasic, all)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio, all)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml)).as("Invalid comparison result").isLessThan(0);
// unspecific to specific
assertThat(comp.compare(audio, audioBasic) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audioBasic) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audio) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML)).as("Invalid comparison result")
.isGreaterThan(0);
assertThat(comp.compare(all, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(all, audio)).as("Invalid comparison result").isGreaterThan(0);
// qualifiers
assertThat(comp.compare(audio, audio07) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio07, audio) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio07, audio03) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio03, audio07) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio03, all) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audio03) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, audio07)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio07, audio)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audio07, audio03)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio03, audio07)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audio03, all)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(all, audio03)).as("Invalid comparison result").isGreaterThan(0);
// other parameters
assertThat(comp.compare(audioBasic, audioBasicLevel) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasicLevel, audioBasic) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, audioBasicLevel)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audioBasicLevel, audioBasic)).as("Invalid comparison result").isLessThan(0);
// different types
assertThat(comp.compare(audioBasic, textHtml)).as("Invalid comparison result").isEqualTo(0);
@@ -409,28 +410,29 @@ public class MediaTypeTests {
assertThat(comp.compare(audioBasicLevel, audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
// specific to unspecific
assertThat(comp.compare(audioBasic, audio) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, all) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, all) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, audio)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audioBasic, all)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio, all)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml)).as("Invalid comparison result").isLessThan(0);
// unspecific to specific
assertThat(comp.compare(audio, audioBasic) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audioBasic) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audio) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(all, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(all, audio)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML)).as("Invalid comparison result")
.isGreaterThan(0);
// qualifiers
assertThat(comp.compare(audio, audio07) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio07, audio) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio07, audio03) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio03, audio07) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio03, all) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(all, audio03) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audio, audio07)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio07, audio)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audio07, audio03)).as("Invalid comparison result").isLessThan(0);
assertThat(comp.compare(audio03, audio07)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audio03, all)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(all, audio03)).as("Invalid comparison result").isLessThan(0);
// other parameters
assertThat(comp.compare(audioBasic, audioBasicLevel) > 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasicLevel, audioBasic) < 0).as("Invalid comparison result").isTrue();
assertThat(comp.compare(audioBasic, audioBasicLevel)).as("Invalid comparison result").isGreaterThan(0);
assertThat(comp.compare(audioBasicLevel, audioBasic)).as("Invalid comparison result").isLessThan(0);
// different types
assertThat(comp.compare(audioBasic, textHtml)).as("Invalid comparison result").isEqualTo(0);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -98,8 +98,9 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
try (ClientHttpResponse response = request.execute()) {
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().containsKey(headerName)).as("Header not found").isTrue();
assertThat(response.getHeaders().get(headerName)).as("Header value not found").isEqualTo(Arrays.asList(headerValue1, headerValue2));
assertThat(response.getHeaders()).as("Header not found").containsKey(headerName);
assertThat(response.getHeaders()).as("Header value not found")
.containsEntry(headerName, Arrays.asList(headerValue1, headerValue2));
byte[] result = FileCopyUtils.copyToByteArray(response.getBody());
assertThat(Arrays.equals(body, result)).as("Invalid body").isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -79,10 +79,10 @@ public class FormHttpMessageReaderTests extends AbstractLeakCheckingTests {
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.readMono(null, request, null).block();
assertThat(result.size()).as("Invalid result").isEqualTo(3);
assertThat(result).as("Invalid result").hasSize(3);
assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values).as("Invalid result").hasSize(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(result.getFirst("name 3")).as("Invalid result").isNull();
@@ -94,10 +94,10 @@ public class FormHttpMessageReaderTests extends AbstractLeakCheckingTests {
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.read(null, request, null).single().block();
assertThat(result.size()).as("Invalid result").isEqualTo(3);
assertThat(result).as("Invalid result").hasSize(3);
assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values).as("Invalid result").hasSize(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(result.getFirst("name 3")).as("Invalid result").isNull();

View File

@@ -130,30 +130,30 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests {
assertThat(requestParts).hasSize(7);
Part part = requestParts.getFirst("name 1");
assertThat(part instanceof FormFieldPart).isTrue();
assertThat(part).isInstanceOf(FormFieldPart.class);
assertThat(part.name()).isEqualTo("name 1");
assertThat(((FormFieldPart) part).value()).isEqualTo("value 1");
List<Part> parts2 = requestParts.get("name 2");
assertThat(parts2).hasSize(2);
part = parts2.get(0);
assertThat(part instanceof FormFieldPart).isTrue();
assertThat(part).isInstanceOf(FormFieldPart.class);
assertThat(part.name()).isEqualTo("name 2");
assertThat(((FormFieldPart) part).value()).isEqualTo("value 2+1");
part = parts2.get(1);
assertThat(part instanceof FormFieldPart).isTrue();
assertThat(part).isInstanceOf(FormFieldPart.class);
assertThat(part.name()).isEqualTo("name 2");
assertThat(((FormFieldPart) part).value()).isEqualTo("value 2+2");
part = requestParts.getFirst("logo");
assertThat(part instanceof FilePart).isTrue();
assertThat(part).isInstanceOf(FilePart.class);
assertThat(part.name()).isEqualTo("logo");
assertThat(((FilePart) part).filename()).isEqualTo("logo.jpg");
assertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
assertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
part = requestParts.getFirst("utf8");
assertThat(part instanceof FilePart).isTrue();
assertThat(part).isInstanceOf(FilePart.class);
assertThat(part.name()).isEqualTo("utf8");
assertThat(((FilePart) part).filename()).isEqualTo("Hall\u00F6le.jpg");
assertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
@@ -233,7 +233,7 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests {
Part part = requestParts.getFirst("logo");
assertThat(part.name()).isEqualTo("logo");
assertThat(part instanceof FilePart).isTrue();
assertThat(part).isInstanceOf(FilePart.class);
assertThat(((FilePart) part).filename()).isEqualTo("logo.jpg");
assertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
assertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
@@ -284,12 +284,12 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTests {
assertThat(requestParts).hasSize(2);
Part part = requestParts.getFirst("resource");
assertThat(part instanceof FilePart).isTrue();
assertThat(part).isInstanceOf(FilePart.class);
assertThat(((FilePart) part).filename()).isEqualTo("spring.jpg");
assertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
part = requestParts.getFirst("buffers");
assertThat(part instanceof FilePart).isTrue();
assertThat(part).isInstanceOf(FilePart.class);
assertThat(((FilePart) part).filename()).isEqualTo("buffers.jpg");
assertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -74,7 +74,7 @@ class BufferedImageHttpMessageConverterTests {
MediaType contentType = new MediaType("image", "png");
converter.write(body, contentType, outputMessage);
assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content type").isEqualTo(contentType);
assertThat(outputMessage.getBodyAsBytes().length > 0).as("Invalid size").isTrue();
assertThat(outputMessage.getBodyAsBytes()).as("Invalid size").isNotEmpty();
BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
assertThat(result.getHeight()).as("Invalid height").isEqualTo(500);
assertThat(result.getWidth()).as("Invalid width").isEqualTo(750);
@@ -89,7 +89,7 @@ class BufferedImageHttpMessageConverterTests {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(body, new MediaType("*", "*"), outputMessage);
assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content type").isEqualTo(contentType);
assertThat(outputMessage.getBodyAsBytes().length > 0).as("Invalid size").isTrue();
assertThat(outputMessage.getBodyAsBytes()).as("Invalid size").isNotEmpty();
BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
assertThat(result.getHeight()).as("Invalid height").isEqualTo(500);
assertThat(result.getWidth()).as("Invalid width").isEqualTo(750);

View File

@@ -124,10 +124,10 @@ public class FormHttpMessageConverterTests {
new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
assertThat(result.size()).as("Invalid result").isEqualTo(3);
assertThat(result).as("Invalid result").hasSize(3);
assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values).as("Invalid result").hasSize(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(result.getFirst("name 3")).as("Invalid result").isNull();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -150,7 +150,7 @@ public class ObjectToStringHttpMessageConverterTests {
this.converter.write((byte) -8, null, this.response);
assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("ISO-8859-1");
assertThat(this.servletResponse.getContentType().startsWith(MediaType.TEXT_PLAIN_VALUE)).isTrue();
assertThat(this.servletResponse.getContentType()).startsWith(MediaType.TEXT_PLAIN_VALUE);
assertThat(this.servletResponse.getContentLength()).isEqualTo(2);
assertThat(this.servletResponse.getContentAsByteArray()).isEqualTo(new byte[] { '-', '8' });
}
@@ -161,7 +161,7 @@ public class ObjectToStringHttpMessageConverterTests {
this.converter.write(958, contentType, this.response);
assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("UTF-16");
assertThat(this.servletResponse.getContentType().startsWith(MediaType.TEXT_PLAIN_VALUE)).isTrue();
assertThat(this.servletResponse.getContentType()).startsWith(MediaType.TEXT_PLAIN_VALUE);
assertThat(this.servletResponse.getContentLength()).isEqualTo(8);
// First two bytes: byte order mark
assertThat(this.servletResponse.getContentAsByteArray()).isEqualTo(new byte[] { -2, -1, 0, '9', 0, '5', 0, '8' });

View File

@@ -63,7 +63,6 @@ class GsonFactoryBeanTests {
Gson gson = this.factory.getObject();
StringBean bean = new StringBean();
bean.setName("Jason");
assertThat(gson.toJson(bean)).contains(" \"name\": \"Jason\"");
}
@@ -129,7 +128,6 @@ class GsonFactoryBeanTests {
cal.set(Calendar.DATE, 1);
Date date = cal.getTime();
bean.setDate(date);
assertThat(gson.toJson(bean))
.startsWith("{\"date\":\"Jan 1, 2014")
.endsWith("12:00:00 AM\"}");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -125,12 +125,12 @@ public class GsonHttpMessageConverterTests {
this.converter.write(body, null, outputMessage);
Charset utf8 = StandardCharsets.UTF_8;
String result = outputMessage.getBodyAsString(utf8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":[1,2]")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":[1,2]");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(new MediaType("application", "json", utf8));
}
@@ -148,12 +148,12 @@ public class GsonHttpMessageConverterTests {
this.converter.write(body, MyBase.class, null, outputMessage);
Charset utf8 = StandardCharsets.UTF_8;
String result = outputMessage.getBodyAsString(utf8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":[1,2]")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":[1,2]");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(new MediaType("application", "json", utf8));
}

View File

@@ -280,7 +280,7 @@ class Jackson2ObjectMapperBuilderTests {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
Path file = Paths.get("foo");
assertThat(new String(objectMapper.writeValueAsBytes(file), "UTF-8").endsWith("foo\"")).isTrue();
assertThat(new String(objectMapper.writeValueAsBytes(file), "UTF-8")).endsWith("foo\"");
Optional<String> optional = Optional.of("test");
assertThat(new String(objectMapper.writeValueAsBytes(optional), "UTF-8")).isEqualTo("\"test\"");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -125,12 +125,12 @@ public class JsonbHttpMessageConverterTests {
this.converter.write(body, null, outputMessage);
Charset utf8 = StandardCharsets.UTF_8;
String result = outputMessage.getBodyAsString(utf8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":[1,2]")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":[1,2]");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(new MediaType("application", "json", utf8));
}
@@ -148,12 +148,12 @@ public class JsonbHttpMessageConverterTests {
this.converter.write(body, MyBase.class, null, outputMessage);
Charset utf8 = StandardCharsets.UTF_8;
String result = outputMessage.getBodyAsString(utf8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":[1,2]")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":[1,2]");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(new MediaType("application", "json", utf8));
}

View File

@@ -163,15 +163,15 @@ public class MappingJackson2HttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
HashMap<String, Object> result = (HashMap<String, Object>) converter.read(HashMap.class, inputMessage);
assertThat(result.get("string")).isEqualTo("Foo");
assertThat(result.get("number")).isEqualTo(42);
assertThat(result).containsEntry("string", "Foo");
assertThat(result).containsEntry("number", 42);
assertThat((Double) result.get("fraction")).isCloseTo(42D, within(0D));
List<String> array = new ArrayList<>();
array.add("Foo");
array.add("Bar");
assertThat(result.get("array")).isEqualTo(array);
assertThat(result.get("bool")).isEqualTo(Boolean.TRUE);
assertThat(result.get("bytes")).isEqualTo("AQI=");
assertThat(result).containsEntry("array", array);
assertThat(result).containsEntry("bool", Boolean.TRUE);
assertThat(result).containsEntry("bytes", "AQI=");
}
@Test
@@ -186,12 +186,12 @@ public class MappingJackson2HttpMessageConverterTests {
body.setBytes(new byte[] {0x1, 0x2});
converter.write(body, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":\"AQI=\"")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":\"AQI=\"");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(MediaType.APPLICATION_JSON);
}
@@ -208,12 +208,12 @@ public class MappingJackson2HttpMessageConverterTests {
body.setBytes(new byte[] {0x1, 0x2});
converter.write(body, MyBase.class, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("fraction\":42.0")).isTrue();
assertThat(result.contains("\"array\":[\"Foo\",\"Bar\"]")).isTrue();
assertThat(result.contains("\"bool\":true")).isTrue();
assertThat(result.contains("\"bytes\":\"AQI=\"")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("fraction\":42.0");
assertThat(result).contains("\"array\":[\"Foo\",\"Bar\"]");
assertThat(result).contains("\"bool\":true");
assertThat(result).contains("\"bytes\":\"AQI=\"");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(MediaType.APPLICATION_JSON);
}
@@ -470,8 +470,8 @@ public class MappingJackson2HttpMessageConverterTests {
this.converter.writeInternal(bean, MyInterface.class, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
}
@Test // SPR-13318
@@ -492,10 +492,10 @@ public class MappingJackson2HttpMessageConverterTests {
this.converter.writeInternal(beans, typeReference.getType(), outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result.contains("\"string\":\"Foo\"")).isTrue();
assertThat(result.contains("\"number\":42")).isTrue();
assertThat(result.contains("\"string\":\"Bar\"")).isTrue();
assertThat(result.contains("\"number\":123")).isTrue();
assertThat(result).contains("\"string\":\"Foo\"");
assertThat(result).contains("\"number\":42");
assertThat(result).contains("\"string\":\"Bar\"");
assertThat(result).contains("\"number\":123");
}
@Test
@@ -575,9 +575,9 @@ public class MappingJackson2HttpMessageConverterTests {
converter.write(body, null, outputMessage1);
customizedConverter.write(body, null, outputMessage2);
String result1 = outputMessage1.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result1.contains("\"property\":\"VAL2\"")).isTrue();
assertThat(result1).contains("\"property\":\"VAL2\"");
String result2 = outputMessage2.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result2.contains("\"property\":\"Value2\"")).isTrue();
assertThat(result2).contains("\"property\":\"Value2\"");
}

View File

@@ -95,7 +95,7 @@ class ProtobufHttpMessageConverterTests {
MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF;
this.converter.write(this.testMsg, contentType, outputMessage);
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(contentType);
assertThat(outputMessage.getBodyAsBytes().length > 0).isTrue();
assertThat(outputMessage.getBodyAsBytes().length).isGreaterThan(0);
Message result = Msg.parseFrom(outputMessage.getBodyAsBytes());
assertThat(result).isEqualTo(this.testMsg);
@@ -119,7 +119,7 @@ class ProtobufHttpMessageConverterTests {
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(contentType);
final String body = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(body.isEmpty()).as("body is empty").isFalse();
assertThat(body).as("body is empty").isNotEmpty();
Msg.Builder builder = Msg.newBuilder();
JsonFormat.parser().merge(body, builder);
@@ -144,7 +144,7 @@ class ProtobufHttpMessageConverterTests {
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(contentType);
String body = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(body.isEmpty()).as("body is empty").isFalse();
assertThat(body).as("body is empty").isNotEmpty();
Msg.Builder builder = Msg.newBuilder();
JsonFormat.parser().merge(body, builder);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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 @@ public class ProtobufJsonFormatHttpMessageConverterTests {
MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF;
this.converter.write(this.testMsg, contentType, outputMessage);
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(contentType);
assertThat(outputMessage.getBodyAsBytes().length > 0).isTrue();
assertThat(outputMessage.getBodyAsBytes().length).isGreaterThan(0);
Message result = Msg.parseFrom(outputMessage.getBodyAsBytes());
assertThat(result).isEqualTo(this.testMsg);

View File

@@ -84,7 +84,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes(StandardCharsets.UTF_8));
List<RootElement> result = (List<RootElement>) converter.read(rootElementListType, null, inputMessage);
assertThat(result.size()).as("Invalid result").isEqualTo(2);
assertThat(result).as("Invalid result").hasSize(2);
assertThat(result.get(0).type.s).as("Invalid result").isEqualTo("1");
assertThat(result.get(1).type.s).as("Invalid result").isEqualTo("2");
}
@@ -96,7 +96,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes(StandardCharsets.UTF_8));
Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage);
assertThat(result.size()).as("Invalid result").isEqualTo(2);
assertThat(result).as("Invalid result").hasSize(2);
assertThat(result.contains(new RootElement("1"))).as("Invalid result").isTrue();
assertThat(result.contains(new RootElement("2"))).as("Invalid result").isTrue();
}
@@ -108,7 +108,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes(StandardCharsets.UTF_8));
List<TestType> result = (List<TestType>) converter.read(typeListType, null, inputMessage);
assertThat(result.size()).as("Invalid result").isEqualTo(2);
assertThat(result).as("Invalid result").hasSize(2);
assertThat(result.get(0).s).as("Invalid result").isEqualTo("1");
assertThat(result.get(1).s).as("Invalid result").isEqualTo("2");
}
@@ -120,7 +120,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes(StandardCharsets.UTF_8));
Set<TestType> result = (Set<TestType>) converter.read(typeSetType, null, inputMessage);
assertThat(result.size()).as("Invalid result").isEqualTo(2);
assertThat(result).as("Invalid result").hasSize(2);
assertThat(result.contains(new TestType("1"))).as("Invalid result").isTrue();
assertThat(result.contains(new TestType("2"))).as("Invalid result").isTrue();
}
@@ -147,7 +147,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
try {
Collection<RootElement> result = converter.read(rootElementListType, null, inputMessage);
assertThat(result).hasSize(1);
assertThat(result.iterator().next().external).isEqualTo("");
assertThat(result.iterator().next().external).isEmpty();
}
catch (HttpMessageNotReadableException ex) {
// Some parsers raise an exception

View File

@@ -132,7 +132,7 @@ public class Jaxb2RootElementHttpMessageConverterTests {
converter.setSupportDtd(true);
RootElement rootElement = (RootElement) converter.read(RootElement.class, inputMessage);
assertThat(rootElement.external).isEqualTo("");
assertThat(rootElement.external).isEmpty();
}
@Test

View File

@@ -97,12 +97,12 @@ public class MappingJackson2XmlHttpMessageConverterTests {
body.setBytes(new byte[]{0x1, 0x2});
converter.write(body, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result.contains("<string>Foo</string>")).isTrue();
assertThat(result.contains("<number>42</number>")).isTrue();
assertThat(result.contains("<fraction>42.0</fraction>")).isTrue();
assertThat(result.contains("<array><array>Foo</array><array>Bar</array></array>")).isTrue();
assertThat(result.contains("<bool>true</bool>")).isTrue();
assertThat(result.contains("<bytes>AQI=</bytes>")).isTrue();
assertThat(result).contains("<string>Foo</string>");
assertThat(result).contains("<number>42</number>");
assertThat(result).contains("<fraction>42.0</fraction>");
assertThat(result).contains("<array><array>Foo</array><array>Bar</array></array>");
assertThat(result).contains("<bool>true</bool>");
assertThat(result).contains("<bytes>AQI=</bytes>");
assertThat(outputMessage.getHeaders().getContentType())
.as("Invalid content-type").isEqualTo(new MediaType("application", "xml", StandardCharsets.UTF_8));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.
@@ -60,7 +60,7 @@ class DefaultRequestPathTests {
void modifyContextPath() {
RequestPath requestPath = RequestPath.parse("/aA/bB/cC", null);
assertThat(requestPath.contextPath().value()).isEqualTo("");
assertThat(requestPath.contextPath().value()).isEmpty();
assertThat(requestPath.pathWithinApplication().value()).isEqualTo("/aA/bB/cC");
requestPath = requestPath.modifyContextPath("/aA");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -44,51 +44,54 @@ public class EscapedErrorsTests {
errors.reject("GENERAL_ERROR \" '", null, "message: \" '");
assertThat(errors.hasErrors()).as("Correct errors flag").isTrue();
assertThat(errors.getErrorCount() == 4).as("Correct number of errors").isTrue();
assertThat("tb".equals(errors.getObjectName())).as("Correct object name").isTrue();
assertThat(errors.getErrorCount()).as("Correct number of errors").isEqualTo(4);
assertThat(errors.getObjectName()).as("Correct object name").isEqualTo("tb");
assertThat(errors.hasGlobalErrors()).as("Correct global errors flag").isTrue();
assertThat(errors.getGlobalErrorCount() == 1).as("Correct number of global errors").isTrue();
assertThat(errors.getGlobalErrorCount()).as("Correct number of global errors").isOne();
ObjectError globalError = errors.getGlobalError();
String defaultMessage = globalError.getDefaultMessage();
assertThat("message: &quot; &#39;".equals(defaultMessage)).as("Global error message escaped").isTrue();
assertThat("GENERAL_ERROR \" '".equals(globalError.getCode())).as("Global error code not escaped").isTrue();
assertThat(defaultMessage).as("Global error message escaped").isEqualTo("message: &quot; &#39;");
assertThat(globalError.getCode()).as("Global error code not escaped").isEqualTo("GENERAL_ERROR \" '");
ObjectError globalErrorInList = errors.getGlobalErrors().get(0);
assertThat(defaultMessage.equals(globalErrorInList.getDefaultMessage())).as("Same global error in list").isTrue();
assertThat(defaultMessage).as("Same global error in list").isEqualTo(globalErrorInList.getDefaultMessage());
ObjectError globalErrorInAllList = errors.getAllErrors().get(3);
assertThat(defaultMessage.equals(globalErrorInAllList.getDefaultMessage())).as("Same global error in list").isTrue();
assertThat(defaultMessage).as("Same global error in list").isEqualTo(globalErrorInAllList.getDefaultMessage());
assertThat(errors.hasFieldErrors()).as("Correct field errors flag").isTrue();
assertThat(errors.getFieldErrorCount() == 3).as("Correct number of field errors").isTrue();
assertThat(errors.getFieldErrors().size() == 3).as("Correct number of field errors in list").isTrue();
assertThat(errors.getFieldErrorCount()).as("Correct number of field errors").isEqualTo(3);
assertThat(errors.getFieldErrors()).as("Correct number of field errors in list").hasSize(3);
FieldError fieldError = errors.getFieldError();
assertThat("NAME_EMPTY &".equals(fieldError.getCode())).as("Field error code not escaped").isTrue();
assertThat("empty &amp;".equals(errors.getFieldValue("name"))).as("Field value escaped").isTrue();
assertThat(fieldError.getCode()).as("Field error code not escaped").isEqualTo("NAME_EMPTY &");
assertThat(errors.getFieldValue("name")).as("Field value escaped").isEqualTo("empty &amp;");
FieldError fieldErrorInList = errors.getFieldErrors().get(0);
assertThat(fieldError.getDefaultMessage().equals(fieldErrorInList.getDefaultMessage())).as("Same field error in list").isTrue();
assertThat(fieldError.getDefaultMessage()).as("Same field error in list")
.isEqualTo(fieldErrorInList.getDefaultMessage());
assertThat(errors.hasFieldErrors("name")).as("Correct name errors flag").isTrue();
assertThat(errors.getFieldErrorCount("name") == 1).as("Correct number of name errors").isTrue();
assertThat(errors.getFieldErrors("name").size() == 1).as("Correct number of name errors in list").isTrue();
assertThat(errors.getFieldErrorCount("name")).as("Correct number of name errors").isOne();
assertThat(errors.getFieldErrors("name")).as("Correct number of name errors in list").hasSize(1);
FieldError nameError = errors.getFieldError("name");
assertThat("message: &amp;".equals(nameError.getDefaultMessage())).as("Name error message escaped").isTrue();
assertThat("NAME_EMPTY &".equals(nameError.getCode())).as("Name error code not escaped").isTrue();
assertThat("empty &amp;".equals(errors.getFieldValue("name"))).as("Name value escaped").isTrue();
assertThat(nameError.getDefaultMessage()).as("Name error message escaped").isEqualTo("message: &amp;");
assertThat(nameError.getCode()).as("Name error code not escaped").isEqualTo("NAME_EMPTY &");
assertThat(errors.getFieldValue("name")).as("Name value escaped").isEqualTo("empty &amp;");
FieldError nameErrorInList = errors.getFieldErrors("name").get(0);
assertThat(nameError.getDefaultMessage().equals(nameErrorInList.getDefaultMessage())).as("Same name error in list").isTrue();
assertThat(nameError.getDefaultMessage()).as("Same name error in list")
.isEqualTo(nameErrorInList.getDefaultMessage());
assertThat(errors.hasFieldErrors("age")).as("Correct age errors flag").isTrue();
assertThat(errors.getFieldErrorCount("age") == 2).as("Correct number of age errors").isTrue();
assertThat(errors.getFieldErrors("age").size() == 2).as("Correct number of age errors in list").isTrue();
assertThat(errors.getFieldErrorCount("age")).as("Correct number of age errors").isEqualTo(2);
assertThat(errors.getFieldErrors("age")).as("Correct number of age errors in list").hasSize(2);
FieldError ageError = errors.getFieldError("age");
assertThat("message: &lt;tag&gt;".equals(ageError.getDefaultMessage())).as("Age error message escaped").isTrue();
assertThat("AGE_NOT_SET <tag>".equals(ageError.getCode())).as("Age error code not escaped").isTrue();
assertThat((Integer.valueOf(0)).equals(errors.getFieldValue("age"))).as("Age value not escaped").isTrue();
assertThat(ageError.getDefaultMessage()).as("Age error message escaped").isEqualTo("message: &lt;tag&gt;");
assertThat(ageError.getCode()).as("Age error code not escaped").isEqualTo("AGE_NOT_SET <tag>");
assertThat((Integer.valueOf(0))).as("Age value not escaped").isEqualTo(errors.getFieldValue("age"));
FieldError ageErrorInList = errors.getFieldErrors("age").get(0);
assertThat(ageError.getDefaultMessage().equals(ageErrorInList.getDefaultMessage())).as("Same name error in list").isTrue();
assertThat(ageError.getDefaultMessage()).as("Same name error in list")
.isEqualTo(ageErrorInList.getDefaultMessage());
FieldError ageError2 = errors.getFieldErrors("age").get(1);
assertThat("message: &lt;tag&gt;".equals(ageError2.getDefaultMessage())).as("Age error 2 message escaped").isTrue();
assertThat("AGE_NOT_32 <tag>".equals(ageError2.getCode())).as("Age error 2 code not escaped").isTrue();
assertThat(ageError2.getDefaultMessage()).as("Age error 2 message escaped").isEqualTo("message: &lt;tag&gt;");
assertThat(ageError2.getCode()).as("Age error 2 code not escaped").isEqualTo("AGE_NOT_32 <tag>");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -216,7 +216,7 @@ public class ServletRequestDataBinderTests {
public void testNoParameters() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertThat(pvs.getPropertyValues().length == 0).as("Found no parameters").isTrue();
assertThat(pvs.getPropertyValues().length).as("Found no parameters").isEqualTo(0);
}
@Test
@@ -226,7 +226,7 @@ public class ServletRequestDataBinderTests {
request.addParameter("forname", original);
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertThat(pvs.getPropertyValues().length == 1).as("Found 1 parameter").isTrue();
assertThat(pvs.getPropertyValues().length).as("Found 1 parameter").isEqualTo(1);
boolean condition = pvs.getPropertyValue("forname").getValue() instanceof String[];
assertThat(condition).as("Found array value").isTrue();
String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
@@ -237,7 +237,7 @@ public class ServletRequestDataBinderTests {
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
assertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
assertThat(pvs.getPropertyValues().length).as("Contains 3").isEqualTo(3);
assertThat(pvs.contains("forname")).as("Contains forname").isTrue();
assertThat(pvs.contains("surname")).as("Contains surname").isTrue();
assertThat(pvs.contains("age")).as("Contains age").isTrue();
@@ -251,13 +251,13 @@ public class ServletRequestDataBinderTests {
m.put("age", "50");
for (PropertyValue element : ps) {
Object val = m.get(element.getName());
assertThat(val != null).as("Can't have unexpected value").isTrue();
assertThat(val).as("Can't have unexpected value").isNotNull();
boolean condition = val instanceof String;
assertThat(condition).as("Val i string").isTrue();
assertThat(val.equals(element.getValue())).as("val matches expected").isTrue();
m.remove(element.getName());
}
assertThat(m.size() == 0).as("Map size is 0").isTrue();
assertThat(m.size()).as("Map size is 0").isEqualTo(0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.
@@ -129,15 +129,15 @@ class ServletRequestUtilsTests {
request.addParameter("paramEmpty", "");
assertThat(ServletRequestUtils.getFloatParameter(request, "param1")).isEqualTo(Float.valueOf(5.5f));
assertThat(ServletRequestUtils.getFloatParameter(request, "param1", 6.5f) == 5.5f).isTrue();
assertThat(ServletRequestUtils.getRequiredFloatParameter(request, "param1") == 5.5f).isTrue();
assertThat(ServletRequestUtils.getFloatParameter(request, "param1", 6.5f)).isEqualTo(5.5f);
assertThat(ServletRequestUtils.getRequiredFloatParameter(request, "param1")).isEqualTo(5.5f);
assertThat(ServletRequestUtils.getFloatParameter(request, "param2", 6.5f) == 6.5f).isTrue();
assertThat(ServletRequestUtils.getFloatParameter(request, "param2", 6.5f)).isEqualTo(6.5f);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredFloatParameter(request, "param2"));
assertThat(ServletRequestUtils.getFloatParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getFloatParameter(request, "param3", 6.5f) == 6.5f).isTrue();
assertThat(ServletRequestUtils.getFloatParameter(request, "param3", 6.5f)).isEqualTo(6.5f);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredFloatParameter(request, "param3"));
@@ -167,15 +167,15 @@ class ServletRequestUtilsTests {
request.addParameter("paramEmpty", "");
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1")).isEqualTo(Double.valueOf(5.5));
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1", 6.5) == 5.5).isTrue();
assertThat(ServletRequestUtils.getRequiredDoubleParameter(request, "param1") == 5.5).isTrue();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param1", 6.5)).isEqualTo(5.5);
assertThat(ServletRequestUtils.getRequiredDoubleParameter(request, "param1")).isEqualTo(5.5);
assertThat(ServletRequestUtils.getDoubleParameter(request, "param2", 6.5) == 6.5).isTrue();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param2", 6.5)).isEqualTo(6.5);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredDoubleParameter(request, "param2"));
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3")).isNull();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3", 6.5) == 6.5).isTrue();
assertThat(ServletRequestUtils.getDoubleParameter(request, "param3", 6.5)).isEqualTo(6.5);
assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() ->
ServletRequestUtils.getRequiredDoubleParameter(request, "param3"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -155,9 +155,9 @@ public class WebRequestDataBinderTests {
request.addParameter("_someMap", "visible");
binder.bind(new ServletWebRequest(request));
assertThat(target.getSomeSet()).isNotNull().isInstanceOf(Set.class);
assertThat(target.getSomeList()).isNotNull().isInstanceOf(List.class);
assertThat(target.getSomeMap()).isNotNull().isInstanceOf(Map.class);
assertThat(target.getSomeSet()).isInstanceOf(Set.class);
assertThat(target.getSomeList()).isInstanceOf(List.class);
assertThat(target.getSomeMap()).isInstanceOf(Map.class);
}
@Test
@@ -319,7 +319,7 @@ public class WebRequestDataBinderTests {
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) throws Exception {
assertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
assertThat(pvs.getPropertyValues().length).as("Contains 3").isEqualTo(3);
assertThat(pvs.contains("forname")).as("Contains forname").isTrue();
assertThat(pvs.contains("surname")).as("Contains surname").isTrue();
assertThat(pvs.contains("age")).as("Contains age").isTrue();
@@ -333,20 +333,20 @@ public class WebRequestDataBinderTests {
m.put("age", "50");
for (PropertyValue pv : pvArray) {
Object val = m.get(pv.getName());
assertThat(val != null).as("Can't have unexpected value").isTrue();
assertThat(val).as("Can't have unexpected value").isNotNull();
boolean condition = val instanceof String;
assertThat(condition).as("Val i string").isTrue();
assertThat(val.equals(pv.getValue())).as("val matches expected").isTrue();
m.remove(pv.getName());
}
assertThat(m.size() == 0).as("Map size is 0").isTrue();
assertThat(m.size()).as("Map size is 0").isEqualTo(0);
}
@Test
public void testNoParameters() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertThat(pvs.getPropertyValues().length == 0).as("Found no parameters").isTrue();
assertThat(pvs.getPropertyValues().length).as("Found no parameters").isEqualTo(0);
}
@Test
@@ -356,7 +356,7 @@ public class WebRequestDataBinderTests {
request.addParameter("forname", original);
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
assertThat(pvs.getPropertyValues().length == 1).as("Found 1 parameter").isTrue();
assertThat(pvs.getPropertyValues().length).as("Found 1 parameter").isEqualTo(1);
boolean condition = pvs.getPropertyValue("forname").getValue() instanceof String[];
assertThat(condition).as("Found array value").isTrue();
String[] values = (String[]) pvs.getPropertyValue("forname").getValue();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -170,7 +170,7 @@ abstract class AbstractMockWebServerTests {
assertThat(line).contains("name=\"" + name + "\"");
assertThat(buffer.readUtf8Line()).startsWith("Content-Type: " + contentType);
assertThat(buffer.readUtf8Line()).isEqualTo("Content-Length: " + value.length());
assertThat(buffer.readUtf8Line()).isEqualTo("");
assertThat(buffer.readUtf8Line()).isEmpty();
assertThat(buffer.readUtf8Line()).isEqualTo(value);
}
@@ -184,7 +184,7 @@ abstract class AbstractMockWebServerTests {
assertThat(line).contains("filename=\"" + filename + "\"");
assertThat(buffer.readUtf8Line()).startsWith("Content-Type: " + contentType);
assertThat(buffer.readUtf8Line()).startsWith("Content-Length: ");
assertThat(buffer.readUtf8Line()).isEqualTo("");
assertThat(buffer.readUtf8Line()).isEmpty();
assertThat(buffer.readUtf8Line()).isNotNull();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -387,9 +387,9 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
bean.setWithout("without");
HttpEntity<MySampleBean> entity = new HttpEntity<>(bean, entityHeaders);
String s = template.postForObject(baseUrl + "/jsonpost", entity, String.class);
assertThat(s.contains("\"with1\":\"with\"")).isTrue();
assertThat(s.contains("\"with2\":\"with\"")).isTrue();
assertThat(s.contains("\"without\":\"without\"")).isTrue();
assertThat(s).contains("\"with1\":\"with\"");
assertThat(s).contains("\"with2\":\"with\"");
assertThat(s).contains("\"without\":\"without\"");
}
@ParameterizedRestTemplateTest
@@ -403,9 +403,9 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
jacksonValue.setSerializationView(MyJacksonView1.class);
HttpEntity<MappingJacksonValue> entity = new HttpEntity<>(jacksonValue, entityHeaders);
String s = template.postForObject(baseUrl + "/jsonpost", entity, String.class);
assertThat(s.contains("\"with1\":\"with\"")).isTrue();
assertThat(s.contains("\"with2\":\"with\"")).isFalse();
assertThat(s.contains("\"without\":\"without\"")).isFalse();
assertThat(s).contains("\"with1\":\"with\"");
assertThat(s).doesNotContain("\"with2\":\"with\"");
assertThat(s).doesNotContain("\"without\":\"without\"");
}
@ParameterizedRestTemplateTest // SPR-12123
@@ -429,8 +429,8 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
.contentType(new MediaType("application", "json", StandardCharsets.UTF_8))
.body(list, typeReference.getType());
String content = template.exchange(entity, String.class).getBody();
assertThat(content.contains("\"type\":\"foo\"")).isTrue();
assertThat(content.contains("\"type\":\"bar\"")).isTrue();
assertThat(content).contains("\"type\":\"foo\"");
assertThat(content).contains("\"type\":\"bar\"");
}
@ParameterizedRestTemplateTest // SPR-15015

View File

@@ -48,7 +48,7 @@ public class ServletContextResourceTests {
assertThat(resource.exists()).isTrue();
assertThat(resource.isFile()).isTrue();
assertThat(resource.getFilename()).isEqualTo("resource.txt");
assertThat(resource.getURL().getFile().endsWith("resource.txt")).isTrue();
assertThat(resource.getURL().getFile()).endsWith("resource.txt");
}
@Test
@@ -56,12 +56,12 @@ public class ServletContextResourceTests {
Resource resource = new ServletContextResource(this.servletContext, TEST_RESOURCE_PATH);
Resource relative1 = resource.createRelative("relative.txt");
assertThat(relative1.getFilename()).isEqualTo("relative.txt");
assertThat(relative1.getURL().getFile().endsWith("relative.txt")).isTrue();
assertThat(relative1.getURL().getFile()).endsWith("relative.txt");
assertThat(relative1.exists()).isTrue();
Resource relative2 = resource.createRelative("folder/other.txt");
assertThat(relative2.getFilename()).isEqualTo("other.txt");
assertThat(relative2.getURL().getFile().endsWith("other.txt")).isTrue();
assertThat(relative2.getURL().getFile()).endsWith("other.txt");
assertThat(relative2.exists()).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.
@@ -196,8 +196,8 @@ public class DefaultCorsProcessorTests {
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header1")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header2")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).contains("header1");
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).contains("header2");
assertThat(this.response.getHeaders(HttpHeaders.VARY)).contains(HttpHeaders.ORIGIN,
HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
@@ -365,9 +365,9 @@ public class DefaultCorsProcessorTests {
this.processor.processRequest(this.conf, this.request, this.response);
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("Header1")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("Header2")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("Header3")).isFalse();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header1");
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header2");
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).doesNotContain("Header3");
assertThat(this.response.getHeaders(HttpHeaders.VARY)).contains(HttpHeaders.ORIGIN,
HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
@@ -385,9 +385,9 @@ public class DefaultCorsProcessorTests {
this.processor.processRequest(this.conf, this.request, this.response);
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("Header1")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("Header2")).isTrue();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS).contains("*")).isFalse();
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header1");
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header2");
assertThat(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)).doesNotContain("*");
assertThat(this.response.getHeaders(HttpHeaders.VARY)).contains(HttpHeaders.ORIGIN,
HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.
@@ -202,8 +202,8 @@ public class DefaultCorsProcessorTests {
assertThat(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
assertThat(response.getHeaders().containsKey(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).isTrue();
assertThat(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header1")).isTrue();
assertThat(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header2")).isTrue();
assertThat(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).contains("header1");
assertThat(response.getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).contains("header2");
assertThat(response.getHeaders().get(VARY)).contains(ORIGIN,
ACCESS_CONTROL_REQUEST_METHOD, ACCESS_CONTROL_REQUEST_HEADERS);
assertThat((Object) response.getStatusCode()).isNull();
@@ -380,9 +380,9 @@ public class DefaultCorsProcessorTests {
ServerHttpResponse response = exchange.getResponse();
assertThat(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_HEADERS)).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("Header1")).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("Header2")).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("Header3")).isFalse();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header1");
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header2");
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).doesNotContain("Header3");
assertThat(response.getHeaders().get(VARY)).contains(ORIGIN,
ACCESS_CONTROL_REQUEST_METHOD, ACCESS_CONTROL_REQUEST_HEADERS);
assertThat((Object) response.getStatusCode()).isNull();
@@ -402,9 +402,9 @@ public class DefaultCorsProcessorTests {
ServerHttpResponse response = exchange.getResponse();
assertThat(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_ORIGIN)).isTrue();
assertThat(response.getHeaders().containsKey(ACCESS_CONTROL_ALLOW_HEADERS)).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("Header1")).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("Header2")).isTrue();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS).contains("*")).isFalse();
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header1");
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).contains("Header2");
assertThat(response.getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS)).doesNotContain("*");
assertThat(response.getHeaders().get(VARY)).contains(ORIGIN,
ACCESS_CONTROL_REQUEST_METHOD, ACCESS_CONTROL_REQUEST_HEADERS);
assertThat((Object) response.getStatusCode()).isNull();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.
@@ -45,7 +45,7 @@ public class ContentCachingResponseWrapperTests {
responseWrapper.copyBodyToResponse();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentLength() > 0).isTrue();
assertThat(response.getContentLength()).isGreaterThan(0);
assertThat(response.getContentAsByteArray()).isEqualTo(responseBody);
}

View File

@@ -214,7 +214,7 @@ public class ForwardedHeaderFilterTests {
@Test
public void contextPathEmpty() throws Exception {
request.addHeader(X_FORWARDED_PREFIX, "");
assertThat(filterAndGetContextPath()).isEqualTo("");
assertThat(filterAndGetContextPath()).isEmpty();
}
@Test
@@ -269,7 +269,7 @@ public class ForwardedHeaderFilterTests {
request.setRequestURI("/app/path");
HttpServletRequest actual = filterAndGetWrappedRequest();
assertThat(actual.getContextPath()).isEqualTo("");
assertThat(actual.getContextPath()).isEmpty();
assertThat(actual.getRequestURI()).isEqualTo("/path");
}
@@ -280,7 +280,7 @@ public class ForwardedHeaderFilterTests {
request.setRequestURI("/app/path/");
HttpServletRequest actual = filterAndGetWrappedRequest();
assertThat(actual.getContextPath()).isEqualTo("");
assertThat(actual.getContextPath()).isEmpty();
assertThat(actual.getRequestURI()).isEqualTo("/path/");
}
@@ -302,7 +302,7 @@ public class ForwardedHeaderFilterTests {
request.setRequestURI("/app");
HttpServletRequest actual = filterAndGetWrappedRequest();
assertThat(actual.getContextPath()).isEqualTo("");
assertThat(actual.getContextPath()).isEmpty();
assertThat(actual.getRequestURI()).isEqualTo("/");
}
@@ -313,7 +313,7 @@ public class ForwardedHeaderFilterTests {
request.setRequestURI("/app/");
HttpServletRequest actual = filterAndGetWrappedRequest();
assertThat(actual.getContextPath()).isEqualTo("");
assertThat(actual.getContextPath()).isEmpty();
assertThat(actual.getRequestURI()).isEqualTo("/");
}
@@ -323,7 +323,7 @@ public class ForwardedHeaderFilterTests {
request.setRequestURI("/path;a=b/with/semicolon");
HttpServletRequest actual = filterAndGetWrappedRequest();
assertThat(actual.getContextPath()).isEqualTo("");
assertThat(actual.getContextPath()).isEmpty();
assertThat(actual.getRequestURI()).isEqualTo("/path;a=b/with/semicolon");
assertThat(actual.getRequestURL().toString()).isEqualTo("http://localhost/path;a=b/with/semicolon");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -74,7 +74,7 @@ public class ShallowEtagHeaderFilterTests {
assertThat(response.getStatus()).as("Invalid status").isEqualTo(200);
assertThat(response.getHeader("ETag")).as("Invalid ETag").isEqualTo("\"0b10a8db164e0754105b7a99be72e3fe5\"");
assertThat(response.getContentLength() > 0).as("Invalid Content-Length header").isTrue();
assertThat(response.getContentLength()).as("Invalid Content-Length header").isGreaterThan(0);
assertThat(response.getContentAsByteArray()).as("Invalid content").isEqualTo(responseBody);
}
@@ -94,7 +94,7 @@ public class ShallowEtagHeaderFilterTests {
assertThat(response.getStatus()).as("Invalid status").isEqualTo(200);
assertThat(response.getHeader("ETag")).as("Invalid ETag").isEqualTo("W/\"0b10a8db164e0754105b7a99be72e3fe5\"");
assertThat(response.getContentLength() > 0).as("Invalid Content-Length header").isTrue();
assertThat(response.getContentLength()).as("Invalid Content-Length header").isGreaterThan(0);
assertThat(response.getContentAsByteArray()).as("Invalid content").isEqualTo(responseBody);
}
@@ -262,7 +262,7 @@ public class ShallowEtagHeaderFilterTests {
assertThat(response.getStatus()).as("Invalid status").isEqualTo(200);
assertThat(response.getHeader("ETag")).as("Invalid ETag").isEqualTo("\"0b10a8db164e0754105b7a99be72e3fe5\"");
assertThat(response.getContentLength() > 0).as("Invalid Content-Length header").isTrue();
assertThat(response.getContentLength()).as("Invalid Content-Length header").isGreaterThan(0);
assertThat(response.getContentAsByteArray()).as("Invalid content").isEqualTo(responseBody);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -137,9 +137,9 @@ class ModelFactoryOrderingTests {
private void assertInvokedBefore(String beforeMethod, String... afterMethods) {
List<String> actual = getInvokedMethods();
for (String afterMethod : afterMethods) {
assertThat(actual.indexOf(beforeMethod) < actual.indexOf(afterMethod))
assertThat(actual.indexOf(beforeMethod))
.as(beforeMethod + " should be before " + afterMethod + ". Actual order: " + actual.toString())
.isTrue();
.isLessThan(actual.indexOf(afterMethod));
}
}

View File

@@ -518,7 +518,7 @@ public class RequestParamMethodArgumentResolverTests {
request.addParameter("name", "123");
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).get()).isEqualTo(123);
assertThat(((Optional) result)).contains(123);
}
@Test
@@ -534,7 +534,7 @@ public class RequestParamMethodArgumentResolverTests {
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
assertThat(((Optional) result)).isNotPresent();
}
@Test
@@ -567,7 +567,7 @@ public class RequestParamMethodArgumentResolverTests {
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
assertThat(((Optional) result)).isNotPresent();
}
@Test
@@ -584,7 +584,7 @@ public class RequestParamMethodArgumentResolverTests {
request.addParameter("name", "123", "456");
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).get()).isEqualTo(Arrays.asList("123", "456"));
assertThat(((Optional) result)).contains(Arrays.asList("123", "456"));
}
@Test
@@ -600,7 +600,7 @@ public class RequestParamMethodArgumentResolverTests {
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
assertThat(((Optional) result)).isNotPresent();
}
@Test

View File

@@ -66,7 +66,7 @@ public class ByteArrayMultipartFileEditorTests {
@Test
public void setValueAsNullGetsBackEmptyString() throws Exception {
editor.setValue(null);
assertThat(editor.getAsText()).isEqualTo("");
assertThat(editor.getAsText()).isEmpty();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -141,7 +141,7 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String value = response.getHeaders().getFirst("Set-Cookie");
assertThat(value).isNotNull();
assertThat(value.contains("Max-Age=0")).as("Actual value: " + value).isTrue();
assertThat(value).as("Actual value: " + value).contains("Max-Age=0");
}
@ParameterizedHttpServerTest
@@ -189,7 +189,7 @@ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTe
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String value = response.getHeaders().getFirst("Set-Cookie");
assertThat(value).isNotNull();
assertThat(value.contains("Max-Age=0")).as("Actual value: " + value).isTrue();
assertThat(value).as("Actual value: " + value).contains("Max-Age=0");
}
private String extractSessionId(HttpHeaders headers) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -44,7 +44,7 @@ class HttpRequestValuesTests {
HttpRequestValues requestValues = HttpRequestValues.builder().setHttpMethod(HttpMethod.GET).build();
assertThat(requestValues.getUri()).isNull();
assertThat(requestValues.getUriTemplate()).isEqualTo("");
assertThat(requestValues.getUriTemplate()).isEmpty();
}
@ParameterizedTest

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -151,7 +151,7 @@ class HttpServiceMethodTests {
HttpRequestValues requestValues = this.client.getRequestValues();
assertThat(requestValues.getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(requestValues.getUriTemplate()).isEqualTo("");
assertThat(requestValues.getUriTemplate()).isEmpty();
assertThat(requestValues.getHeaders().getContentType()).isNull();
assertThat(requestValues.getHeaders().getAccept()).isEmpty();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -50,7 +50,7 @@ class RequestParamArgumentResolverTests {
this.service.postForm("value 1", "value 2");
Object body = this.client.getRequestValues().getBodyValue();
assertThat(body).isNotNull().isInstanceOf(MultiValueMap.class);
assertThat(body).isInstanceOf(MultiValueMap.class);
assertThat((MultiValueMap<String, String>) body).hasSize(2)
.containsEntry("param1", List.of("value 1"))
.containsEntry("param2", List.of("value 2"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -64,7 +64,7 @@ class RequestPartArgumentResolverTests {
this.service.postMultipart("part 1", part2, Mono.just("part 3"));
Object body = this.client.getRequestValues().getBodyValue();
assertThat(body).isNotNull().isInstanceOf(MultiValueMap.class);
assertThat(body).isInstanceOf(MultiValueMap.class);
@SuppressWarnings("unchecked")
MultiValueMap<String, HttpEntity<?>> map = (MultiValueMap<String, HttpEntity<?>>) body;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -100,7 +100,7 @@ public class ContentCachingRequestWrapperTests {
assertThat(wrapper.getParameterMap().isEmpty()).isFalse();
assertThat(new String(wrapper.getContentAsByteArray())).isEqualTo("first=value&second=foo&second=bar");
// SPR-12810 : inputstream body should be consumed
assertThat(new String(FileCopyUtils.copyToByteArray(wrapper.getInputStream()))).isEqualTo("");
assertThat(new String(FileCopyUtils.copyToByteArray(wrapper.getInputStream()))).isEmpty();
}
@Test // SPR-12810

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -47,7 +47,7 @@ public class HtmlUtilsTests {
@Test
void testEncodeIntoHtmlCharacterSet() {
assertThat(HtmlUtils.htmlEscape("")).as("An empty string should be converted to an empty string").isEqualTo("");
assertThat(HtmlUtils.htmlEscape("")).as("An empty string should be converted to an empty string").isEmpty();
assertThat(HtmlUtils.htmlEscape("A sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("A sentence containing no special characters.");
assertThat(HtmlUtils.htmlEscape("< >")).as("'< >' should be encoded to '&lt; &gt;'").isEqualTo("&lt; &gt;");
@@ -64,7 +64,8 @@ public class HtmlUtilsTests {
@Test
void testEncodeIntoHtmlCharacterSetFromUtf8() {
String utf8 = ("UTF-8");
assertThat(HtmlUtils.htmlEscape("", utf8)).as("An empty string should be converted to an empty string").isEqualTo("");
assertThat(HtmlUtils.htmlEscape("", utf8)).as("An empty string should be converted to an empty string")
.isEmpty();
assertThat(HtmlUtils.htmlEscape("A sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("A sentence containing no special characters.");
assertThat(HtmlUtils.htmlEscape("< >", utf8)).as("'< >' should be encoded to '&lt; &gt;'").isEqualTo("&lt; &gt;");
@@ -75,7 +76,7 @@ public class HtmlUtilsTests {
@Test
void testDecodeFromHtmlCharacterSet() {
assertThat(HtmlUtils.htmlUnescape("")).as("An empty string should be converted to an empty string").isEqualTo("");
assertThat(HtmlUtils.htmlUnescape("")).as("An empty string should be converted to an empty string").isEmpty();
assertThat(HtmlUtils.htmlUnescape("This is a sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("This is a sentence containing no special characters.");
assertThat(HtmlUtils.htmlUnescape("A&nbsp;B")).as("'A&nbsp;B' should be decoded to 'A B'").isEqualTo(("A" + (char) 160 + "B"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -953,7 +953,7 @@ class UriComponentsBuilderTests {
void queryParamWithoutValueWithEquals() {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=").build();
assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar=");
assertThat(uriComponents.getQueryParams().get("bar").get(0)).isEqualTo("");
assertThat(uriComponents.getQueryParams().get("bar").get(0)).isEmpty();
}
@Test
@@ -1026,7 +1026,7 @@ class UriComponentsBuilderTests {
@Test // SPR-13257
void parsesEmptyUri() {
UriComponents components = UriComponentsBuilder.fromUriString("").build();
assertThat(components.toString()).isEqualTo("");
assertThat(components.toString()).isEmpty();
}
@Test // gh-25243

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
@@ -100,7 +100,7 @@ public class UriUtilsTests {
@Test
public void decode() {
assertThat(UriUtils.decode("", CHARSET)).as("Invalid encoded URI").isEqualTo("");
assertThat(UriUtils.decode("", CHARSET)).as("Invalid encoded URI").isEmpty();
assertThat(UriUtils.decode("foobar", CHARSET)).as("Invalid encoded URI").isEqualTo("foobar");
assertThat(UriUtils.decode("foo%20bar", CHARSET)).as("Invalid encoded URI").isEqualTo("foo bar");
assertThat(UriUtils.decode("foo%2bbar", CHARSET)).as("Invalid encoded URI").isEqualTo("foo+bar");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -67,7 +67,7 @@ public class WebUtilsTests {
variables = WebUtils.parseMatrixVariables("year");
assertThat(variables).hasSize(1);
assertThat(variables.getFirst("year")).isEqualTo("");
assertThat(variables.getFirst("year")).isEmpty();
variables = WebUtils.parseMatrixVariables("year=2012");
assertThat(variables).hasSize(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.
@@ -394,7 +394,7 @@ public class PathPatternParserTests {
// Based purely on catchAll
p1 = parse("{*foobar}");
p2 = parse("{*goo}");
assertThat(p1.compareTo(p2) != 0).isTrue();
assertThat(p1.compareTo(p2)).isNotEqualTo(0);
p1 = parse("/{*foobar}");
p2 = parse("/abc/{*ww}");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -129,26 +129,44 @@ public class PathPatternTests {
// CaptureVariablePathElement
pp = parse("/{var}");
assertMatches(pp,"/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables().get("var")).isEqualTo("resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables()).containsEntry("var", "resource");
assertMatches(pp,"/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")).isEqualTo("resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables()).containsEntry(
"var",
"resource"
);
assertNoMatch(pp,"/resource//");
pp = parse("/{var}/");
assertNoMatch(pp,"/resource");
assertMatches(pp,"/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")).isEqualTo("resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables()).containsEntry(
"var",
"resource"
);
assertNoMatch(pp,"/resource//");
// CaptureTheRestPathElement
pp = parse("/{*var}");
assertMatches(pp,"/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables().get("var")).isEqualTo("/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables()).containsEntry(
"var",
"/resource"
);
assertMatches(pp,"/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")).isEqualTo("/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables()).containsEntry(
"var",
"/resource/"
);
assertMatches(pp,"/resource//");
assertThat(pp.matchAndExtract(toPathContainer("/resource//")).getUriVariables().get("var")).isEqualTo("/resource//");
assertThat(pp.matchAndExtract(toPathContainer("/resource//")).getUriVariables()).containsEntry(
"var",
"/resource//"
);
assertMatches(pp,"//resource//");
assertThat(pp.matchAndExtract(toPathContainer("//resource//")).getUriVariables().get("var")).isEqualTo("//resource//");
assertThat(pp.matchAndExtract(toPathContainer("//resource//")).getUriVariables()).containsEntry(
"var",
"//resource//"
);
// WildcardTheRestPathElement
pp = parse("/**");
@@ -170,17 +188,17 @@ public class PathPatternTests {
// RegexPathElement
pp = parse("/{var1}_{var2}");
assertMatches(pp,"/res1_res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables().get("var1")).isEqualTo("res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables().get("var2")).isEqualTo("res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables()).containsEntry("var1", "res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables()).containsEntry("var2", "res2");
assertMatches(pp,"/res1_res2/");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var1")).isEqualTo("res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var2")).isEqualTo("res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var1", "res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var2", "res2");
assertNoMatch(pp,"/res1_res2//");
pp = parse("/{var1}_{var2}/");
assertNoMatch(pp,"/res1_res2");
assertMatches(pp,"/res1_res2/");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var1")).isEqualTo("res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var2")).isEqualTo("res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var1", "res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var2", "res2");
assertNoMatch(pp,"/res1_res2//");
pp = parse("/{var1}*");
assertMatches(pp,"/a");
@@ -214,25 +232,40 @@ public class PathPatternTests {
// CaptureVariablePathElement
pp = parser.parse("/{var}");
assertMatches(pp,"/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables().get("var")).isEqualTo("resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables()).containsEntry("var", "resource");
assertNoMatch(pp,"/resource/");
assertNoMatch(pp,"/resource//");
pp = parser.parse("/{var}/");
assertNoMatch(pp,"/resource");
assertMatches(pp,"/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")).isEqualTo("resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables()).containsEntry(
"var",
"resource"
);
assertNoMatch(pp,"/resource//");
// CaptureTheRestPathElement
pp = parser.parse("/{*var}");
assertMatches(pp,"/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables().get("var")).isEqualTo("/resource");
assertThat(pp.matchAndExtract(toPathContainer("/resource")).getUriVariables()).containsEntry(
"var",
"/resource"
);
assertMatches(pp,"/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")).isEqualTo("/resource/");
assertThat(pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables()).containsEntry(
"var",
"/resource/"
);
assertMatches(pp,"/resource//");
assertThat(pp.matchAndExtract(toPathContainer("/resource//")).getUriVariables().get("var")).isEqualTo("/resource//");
assertThat(pp.matchAndExtract(toPathContainer("/resource//")).getUriVariables()).containsEntry(
"var",
"/resource//"
);
assertMatches(pp,"//resource//");
assertThat(pp.matchAndExtract(toPathContainer("//resource//")).getUriVariables().get("var")).isEqualTo("//resource//");
assertThat(pp.matchAndExtract(toPathContainer("//resource//")).getUriVariables()).containsEntry(
"var",
"//resource//"
);
// WildcardTheRestPathElement
pp = parser.parse("/**");
@@ -254,15 +287,15 @@ public class PathPatternTests {
// RegexPathElement
pp = parser.parse("/{var1}_{var2}");
assertMatches(pp,"/res1_res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables().get("var1")).isEqualTo("res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables().get("var2")).isEqualTo("res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables()).containsEntry("var1", "res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2")).getUriVariables()).containsEntry("var2", "res2");
assertNoMatch(pp,"/res1_res2/");
assertNoMatch(pp,"/res1_res2//");
pp = parser.parse("/{var1}_{var2}/");
assertNoMatch(pp,"/res1_res2");
assertMatches(pp,"/res1_res2/");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var1")).isEqualTo("res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables().get("var2")).isEqualTo("res2");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var1", "res1");
assertThat(pp.matchAndExtract(toPathContainer("/res1_res2/")).getUriVariables()).containsEntry("var2", "res2");
assertNoMatch(pp,"/res1_res2//");
pp = parser.parse("/{var1}*");
assertMatches(pp,"/a");
@@ -280,12 +313,12 @@ public class PathPatternTests {
assertThat(getPathRemaining("/*", "/foo/bar").getPathRemaining().value()).isEqualTo("/bar");
assertThat(getPathRemaining("/{foo}", "/foo/bar").getPathRemaining().value()).isEqualTo("/bar");
assertThat(getPathRemaining("/foo","/bar/baz")).isNull();
assertThat(getPathRemaining("/**", "/foo/bar").getPathRemaining().value()).isEqualTo("");
assertThat(getPathRemaining("/{*bar}", "/foo/bar").getPathRemaining().value()).isEqualTo("");
assertThat(getPathRemaining("/**", "/foo/bar").getPathRemaining().value()).isEmpty();
assertThat(getPathRemaining("/{*bar}", "/foo/bar").getPathRemaining().value()).isEmpty();
assertThat(getPathRemaining("/a?b/d?e", "/aab/dde/bar").getPathRemaining().value()).isEqualTo("/bar");
assertThat(getPathRemaining("/{abc}abc", "/xyzabc/bar").getPathRemaining().value()).isEqualTo("/bar");
assertThat(getPathRemaining("/*y*", "/xyzxyz/bar").getPathRemaining().value()).isEqualTo("/bar");
assertThat(getPathRemaining("/", "/").getPathRemaining().value()).isEqualTo("");
assertThat(getPathRemaining("/", "/").getPathRemaining().value()).isEmpty();
assertThat(getPathRemaining("/", "/a").getPathRemaining().value()).isEqualTo("a");
assertThat(getPathRemaining("/", "/a/").getPathRemaining().value()).isEqualTo("a/");
assertThat(getPathRemaining("/a{abc}", "/a/bar").getPathRemaining().value()).isEqualTo("/bar");
@@ -337,34 +370,34 @@ public class PathPatternTests {
// 'the match' it starts with a separator
assertThat(parse("/resource/**").matchStartOfPath(toPathContainer("/resourceX"))).isNull();
assertThat(parse("/resource/**")
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value()).isEqualTo("");
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value()).isEmpty();
// Similar to above for the capture-the-rest variant
assertThat(parse("/resource/{*foo}").matchStartOfPath(toPathContainer("/resourceX"))).isNull();
assertThat(parse("/resource/{*foo}")
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value()).isEqualTo("");
.matchStartOfPath(toPathContainer("/resource")).getPathRemaining().value()).isEmpty();
PathPattern.PathRemainingMatchInfo pri = parse("/aaa/{bbb}/c?d/e*f/*/g")
.matchStartOfPath(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
assertThat(pri).isNotNull();
assertThat(pri.getPathRemaining().value()).isEqualTo("/i");
assertThat(pri.getUriVariables().get("bbb")).isEqualTo("b");
assertThat(pri.getUriVariables()).containsEntry("bbb", "b");
pri = parse("/aaa/{bbb}/c?d/e*f/*/g/").matchStartOfPath(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
assertThat(pri).isNotNull();
assertThat(pri.getPathRemaining().value()).isEqualTo("i");
assertThat(pri.getUriVariables().get("bbb")).isEqualTo("b");
assertThat(pri.getUriVariables()).containsEntry("bbb", "b");
pri = parse("/{aaa}_{bbb}/e*f/{x}/g").matchStartOfPath(toPathContainer("/aa_bb/ef/x/g/i"));
assertThat(pri).isNotNull();
assertThat(pri.getPathRemaining().value()).isEqualTo("/i");
assertThat(pri.getUriVariables().get("aaa")).isEqualTo("aa");
assertThat(pri.getUriVariables().get("bbb")).isEqualTo("bb");
assertThat(pri.getUriVariables().get("x")).isEqualTo("x");
assertThat(pri.getUriVariables()).containsEntry("aaa", "aa");
assertThat(pri.getUriVariables()).containsEntry("bbb", "bb");
assertThat(pri.getUriVariables()).containsEntry("x", "x");
assertThat(parse("/a/b").matchStartOfPath(toPathContainer(""))).isNull();
assertThat(parse("").matchStartOfPath(toPathContainer("/a/b")).getPathRemaining().value()).isEqualTo("/a/b");
assertThat(parse("").matchStartOfPath(toPathContainer("")).getPathRemaining().value()).isEqualTo("");
assertThat(parse("").matchStartOfPath(toPathContainer("")).getPathRemaining().value()).isEmpty();
}
@Test
@@ -563,19 +596,19 @@ public class PathPatternTests {
pri = getPathRemaining(pp, "/foo/bar/goo/boo");
assertThat(pri.getPathRemaining().value()).isEqualTo("/boo");
assertThat(pri.getPathMatched().value()).isEqualTo("/foo/bar/goo");
assertThat(pri.getUriVariables().get("this")).isEqualTo("foo");
assertThat(pri.getUriVariables().get("one")).isEqualTo("bar");
assertThat(pri.getUriVariables().get("here")).isEqualTo("goo");
assertThat(pri.getUriVariables()).containsEntry("this", "foo");
assertThat(pri.getUriVariables()).containsEntry("one", "bar");
assertThat(pri.getUriVariables()).containsEntry("here", "goo");
pp = parse("/aaa/{foo}");
pri = getPathRemaining(pp, "/aaa/bbb");
assertThat(pri.getPathRemaining().value()).isEqualTo("");
assertThat(pri.getPathRemaining().value()).isEmpty();
assertThat(pri.getPathMatched().value()).isEqualTo("/aaa/bbb");
assertThat(pri.getUriVariables().get("foo")).isEqualTo("bbb");
assertThat(pri.getUriVariables()).containsEntry("foo", "bbb");
pp = parse("/aaa/bbb");
pri = getPathRemaining(pp, "/aaa/bbb");
assertThat(pri.getPathRemaining().value()).isEqualTo("");
assertThat(pri.getPathRemaining().value()).isEmpty();
assertThat(pri.getPathMatched().value()).isEqualTo("/aaa/bbb");
assertThat(pri.getUriVariables()).isEmpty();
@@ -583,12 +616,12 @@ public class PathPatternTests {
pri = getPathRemaining(pp, "/foo");
assertThat((Object) pri).isNull();
pri = getPathRemaining(pp, "/abc/def/bhi");
assertThat(pri.getPathRemaining().value()).isEqualTo("");
assertThat(pri.getUriVariables().get("foo")).isEqualTo("def");
assertThat(pri.getPathRemaining().value()).isEmpty();
assertThat(pri.getUriVariables()).containsEntry("foo", "def");
pri = getPathRemaining(pp, "/abc/def/bhi/jkl");
assertThat(pri.getPathRemaining().value()).isEqualTo("/jkl");
assertThat(pri.getUriVariables().get("foo")).isEqualTo("def");
assertThat(pri.getUriVariables()).containsEntry("foo", "def");
}
@Test
@@ -787,8 +820,8 @@ public class PathPatternTests {
assertThat(new AntPathMatcher().match("/*", "/")).isTrue();
assertThat(new AntPathMatcher().match("/*{foo}", "/")).isFalse();
Map<String, String> vars = new AntPathMatcher().extractUriTemplateVariables("/{foo}{bar}", "/a");
assertThat(vars.get("foo")).isEqualTo("a");
assertThat(vars.get("bar")).isEqualTo("");
assertThat(vars).containsEntry("foo", "a");
assertThat(vars.get("bar")).isEmpty();
}
@Test
@@ -829,13 +862,13 @@ public class PathPatternTests {
p = pp.parse("{symbolicName:[\\w\\.]+}-{version:[\\w\\.]+}.jar");
PathPattern.PathMatchInfo result = matchAndExtract(p, "com.example-1.0.0.jar");
assertThat(result.getUriVariables().get("symbolicName")).isEqualTo("com.example");
assertThat(result.getUriVariables().get("version")).isEqualTo("1.0.0");
assertThat(result.getUriVariables()).containsEntry("symbolicName", "com.example");
assertThat(result.getUriVariables()).containsEntry("version", "1.0.0");
p = pp.parse("{symbolicName:[\\w\\.]+}-sources-{version:[\\w\\.]+}.jar");
result = matchAndExtract(p, "com.example-sources-1.0.0.jar");
assertThat(result.getUriVariables().get("symbolicName")).isEqualTo("com.example");
assertThat(result.getUriVariables().get("version")).isEqualTo("1.0.0");
assertThat(result.getUriVariables()).containsEntry("symbolicName", "com.example");
assertThat(result.getUriVariables()).containsEntry("version", "1.0.0");
}
@Test
@@ -844,22 +877,22 @@ public class PathPatternTests {
PathPattern p = pp.parse("{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.]+}.jar");
PathPattern.PathMatchInfo result = p.matchAndExtract(toPathContainer("com.example-sources-1.0.0.jar"));
assertThat(result.getUriVariables().get("symbolicName")).isEqualTo("com.example");
assertThat(result.getUriVariables().get("version")).isEqualTo("1.0.0");
assertThat(result.getUriVariables()).containsEntry("symbolicName", "com.example");
assertThat(result.getUriVariables()).containsEntry("version", "1.0.0");
p = pp.parse("{symbolicName:[\\w\\.]+}-sources-" +
"{version:[\\d\\.]+}-{year:\\d{4}}{month:\\d{2}}{day:\\d{2}}.jar");
result = matchAndExtract(p,"com.example-sources-1.0.0-20100220.jar");
assertThat(result.getUriVariables().get("symbolicName")).isEqualTo("com.example");
assertThat(result.getUriVariables().get("version")).isEqualTo("1.0.0");
assertThat(result.getUriVariables().get("year")).isEqualTo("2010");
assertThat(result.getUriVariables().get("month")).isEqualTo("02");
assertThat(result.getUriVariables().get("day")).isEqualTo("20");
assertThat(result.getUriVariables()).containsEntry("symbolicName", "com.example");
assertThat(result.getUriVariables()).containsEntry("version", "1.0.0");
assertThat(result.getUriVariables()).containsEntry("year", "2010");
assertThat(result.getUriVariables()).containsEntry("month", "02");
assertThat(result.getUriVariables()).containsEntry("day", "20");
p = pp.parse("{symbolicName:[\\p{L}\\.]+}-sources-{version:[\\p{N}\\.\\{\\}]+}.jar");
result = matchAndExtract(p, "com.example-sources-1.0.0.{12}.jar");
assertThat(result.getUriVariables().get("symbolicName")).isEqualTo("com.example");
assertThat(result.getUriVariables().get("version")).isEqualTo("1.0.0.{12}");
assertThat(result.getUriVariables()).containsEntry("symbolicName", "com.example");
assertThat(result.getUriVariables()).containsEntry("version", "1.0.0.{12}");
}
@Test
@@ -874,7 +907,7 @@ public class PathPatternTests {
@Test
public void combine() {
TestPathCombiner pathMatcher = new TestPathCombiner();
assertThat(pathMatcher.combine("", "")).isEqualTo("");
assertThat(pathMatcher.combine("", "")).isEmpty();
assertThat(pathMatcher.combine("/hotels", "")).isEqualTo("/hotels");
assertThat(pathMatcher.combine("", "/hotels")).isEqualTo("/hotels");
assertThat(pathMatcher.combine("/hotels/*", "booking")).isEqualTo("/hotels/booking");
@@ -984,8 +1017,8 @@ public class PathPatternTests {
PathPattern.PathMatchInfo r2 = matchAndExtract(p2, "/file.txt");
// works fine
assertThat(r1.getUriVariables().get("foo")).isEqualTo("file.txt");
assertThat(r2.getUriVariables().get("foo")).isEqualTo("file");
assertThat(r1.getUriVariables()).containsEntry("foo", "file.txt");
assertThat(r2.getUriVariables()).containsEntry("foo", "file");
// This produces 2 (see comments in https://jira.spring.io/browse/SPR-14544 )
// Comparator<String> patternComparator = new AntPathMatcher().getPatternComparator("");
@@ -996,9 +1029,9 @@ public class PathPatternTests {
@Test
public void patternCompareWithNull() {
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, null) == 0).isTrue();
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(parse("/abc"), null) < 0).isTrue();
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, parse("/abc")) > 0).isTrue();
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, null)).isEqualTo(0);
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(parse("/abc"), null)).isLessThan(0);
assertThat(PathPattern.SPECIFICITY_COMPARATOR.compare(null, parse("/abc"))).isGreaterThan(0);
}
@Test
@@ -1115,32 +1148,32 @@ public class PathPatternTests {
public void parameters() {
// CaptureVariablePathElement
PathPattern.PathMatchInfo result = matchAndExtract("/abc/{var}","/abc/one;two=three;four=five");
assertThat(result.getUriVariables().get("var")).isEqualTo("one");
assertThat(result.getUriVariables()).containsEntry("var", "one");
assertThat(result.getMatrixVariables().get("var").getFirst("two")).isEqualTo("three");
assertThat(result.getMatrixVariables().get("var").getFirst("four")).isEqualTo("five");
// RegexPathElement
result = matchAndExtract("/abc/{var1}_{var2}","/abc/123_456;a=b;c=d");
assertThat(result.getUriVariables().get("var1")).isEqualTo("123");
assertThat(result.getUriVariables().get("var2")).isEqualTo("456");
assertThat(result.getUriVariables()).containsEntry("var1", "123");
assertThat(result.getUriVariables()).containsEntry("var2", "456");
// vars associated with second variable
assertThat(result.getMatrixVariables().get("var1")).isNull();
assertThat(result.getMatrixVariables().get("var1")).isNull();
assertThat(result.getMatrixVariables()).doesNotContainKey("var1");
assertThat(result.getMatrixVariables()).doesNotContainKey("var1");
assertThat(result.getMatrixVariables().get("var2").getFirst("a")).isEqualTo("b");
assertThat(result.getMatrixVariables().get("var2").getFirst("c")).isEqualTo("d");
// CaptureTheRestPathElement
result = matchAndExtract("/{*var}","/abc/123_456;a=b;c=d");
assertThat(result.getUriVariables().get("var")).isEqualTo("/abc/123_456");
assertThat(result.getUriVariables()).containsEntry("var", "/abc/123_456");
assertThat(result.getMatrixVariables().get("var").getFirst("a")).isEqualTo("b");
assertThat(result.getMatrixVariables().get("var").getFirst("c")).isEqualTo("d");
result = matchAndExtract("/{*var}","/abc/123_456;a=b;c=d/789;a=e;f=g");
assertThat(result.getUriVariables().get("var")).isEqualTo("/abc/123_456/789");
assertThat(result.getUriVariables()).containsEntry("var", "/abc/123_456/789");
assertThat(result.getMatrixVariables().get("var").get("a").toString()).isEqualTo("[b, e]");
assertThat(result.getMatrixVariables().get("var").getFirst("c")).isEqualTo("d");
assertThat(result.getMatrixVariables().get("var").getFirst("f")).isEqualTo("g");
result = matchAndExtract("/abc/{var}","/abc/one");
assertThat(result.getUriVariables().get("var")).isEqualTo("one");
assertThat(result.getMatrixVariables().get("var")).isNull();
assertThat(result.getUriVariables()).containsEntry("var", "one");
assertThat(result.getMatrixVariables()).doesNotContainKey("var");
result = matchAndExtract("","");
assertThat(result).isNotNull();