11/*
2- * Copyright 2002-2019 the original author or authors.
2+ * Copyright 2002-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717
1818import java .io .IOException ;
1919import java .time .Duration ;
20+ import java .util .Collections ;
2021import java .util .List ;
2122
2223import org .junit .jupiter .api .Test ;
24+ import reactor .core .publisher .Mono ;
2325
2426import org .springframework .core .io .ClassPathResource ;
2527import org .springframework .core .io .FileUrlResource ;
2628import org .springframework .core .io .Resource ;
2729import org .springframework .core .io .UrlResource ;
2830
29- import static java .util .Collections .singletonList ;
3031import static org .assertj .core .api .Assertions .assertThat ;
3132import static org .assertj .core .api .Assertions .fail ;
3233
@@ -46,7 +47,7 @@ public class PathResourceResolverTests {
4647 public void resolveFromClasspath () throws IOException {
4748 Resource location = new ClassPathResource ("test/" , PathResourceResolver .class );
4849 String path = "bar.css" ;
49- List <Resource > locations = singletonList (location );
50+ List <Resource > locations = Collections . singletonList (location );
5051 Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
5152
5253 assertThat (actual ).isEqualTo (location .createRelative (path ));
@@ -56,7 +57,7 @@ public void resolveFromClasspath() throws IOException {
5657 public void resolveFromClasspathRoot () {
5758 Resource location = new ClassPathResource ("/" );
5859 String path = "org/springframework/web/reactive/resource/test/bar.css" ;
59- List <Resource > locations = singletonList (location );
60+ List <Resource > locations = Collections . singletonList (location );
6061 Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
6162
6263 assertThat (actual ).isNotNull ();
@@ -71,7 +72,7 @@ public void resolveWithEncodedPath() throws IOException {
7172
7273 private void testWithEncodedPath (Resource location ) throws IOException {
7374 String path = "foo%20foo.txt" ;
74- List <Resource > locations = singletonList (location );
75+ List <Resource > locations = Collections . singletonList (location );
7576 Resource actual = this .resolver .resolveResource (null , path , locations , null ).block (TIMEOUT );
7677
7778 assertThat (actual ).isNotNull ();
@@ -98,7 +99,7 @@ public void checkResource() throws IOException {
9899 }
99100
100101 private void testCheckResource (Resource location , String requestPath ) throws IOException {
101- List <Resource > locations = singletonList (location );
102+ List <Resource > locations = Collections . singletonList (location );
102103 Resource actual = this .resolver .resolveResource (null , requestPath , locations , null ).block (TIMEOUT );
103104 if (!location .createRelative (requestPath ).exists () && !requestPath .contains (":" )) {
104105 fail (requestPath + " doesn't actually exist as a relative path" );
@@ -122,17 +123,20 @@ public void checkResourceWithAllowedLocations() {
122123
123124 Resource location = getResource ("main.css" );
124125 String actual = this .resolver .resolveUrlPath ("../testalternatepath/bar.css" ,
125- singletonList (location ), null ).block (TIMEOUT );
126+ Collections . singletonList (location ), null ).block (TIMEOUT );
126127
127128 assertThat (actual ).isEqualTo ("../testalternatepath/bar.css" );
128129 }
129130
130131 @ Test // SPR-12624
131132 public void checkRelativeLocation () throws Exception {
132- String locationUrl = new UrlResource (getClass ().getResource ("./test/" )).getURL ().toExternalForm ();
133- Resource location = new UrlResource (locationUrl .replace ("/springframework" ,"/../org/springframework" ));
134- List <Resource > locations = singletonList (location );
135- assertThat (this .resolver .resolveResource (null , "main.css" , locations , null ).block (TIMEOUT )).isNotNull ();
133+ String location = new UrlResource (getClass ().getResource ("./test/" )).getURL ().toExternalForm ();
134+ location = location .replace ("/test/org/springframework" ,"/test/org/../org/springframework" );
135+
136+ Mono <Resource > resourceMono = this .resolver .resolveResource (
137+ null , "main.css" , Collections .singletonList (new UrlResource (location )), null );
138+
139+ assertThat (resourceMono .block (TIMEOUT )).isNotNull ();
136140 }
137141
138142 @ Test // SPR-12747
@@ -145,7 +149,7 @@ public void checkFileLocation() throws Exception {
145149 public void resolvePathRootResource () {
146150 Resource webjarsLocation = new ClassPathResource ("/META-INF/resources/webjars/" , PathResourceResolver .class );
147151 String path = this .resolver .resolveUrlPathInternal (
148- "" , singletonList (webjarsLocation ), null ).block (TIMEOUT );
152+ "" , Collections . singletonList (webjarsLocation ), null ).block (TIMEOUT );
149153
150154 assertThat (path ).isNull ();
151155 }
0 commit comments