Remove duplicate ClassPathResourceTests class
This commit is contained in:
@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@@ -50,6 +51,43 @@ class ClassPathResourceTests {
|
|||||||
private static final String ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE_WITH_LEADING_SLASH = '/' + ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE;
|
private static final String ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE_WITH_LEADING_SLASH = '/' + ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE;
|
||||||
|
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class EqualsAndHashCode {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void equalsAndHashCode() {
|
||||||
|
Resource resource1 = new ClassPathResource("org/springframework/core/io/Resource.class");
|
||||||
|
Resource resource2 = new ClassPathResource("org/springframework/core/../core/io/./Resource.class");
|
||||||
|
Resource resource3 = new ClassPathResource("org/springframework/core/").createRelative("../core/io/./Resource.class");
|
||||||
|
|
||||||
|
assertThat(resource2).isEqualTo(resource1);
|
||||||
|
assertThat(resource3).isEqualTo(resource1);
|
||||||
|
assertThat(resource2).hasSameHashCodeAs(resource1);
|
||||||
|
assertThat(resource3).hasSameHashCodeAs(resource1);
|
||||||
|
|
||||||
|
// Check whether equal/hashCode works in a HashSet.
|
||||||
|
HashSet<Resource> resources = new HashSet<>();
|
||||||
|
resources.add(resource1);
|
||||||
|
resources.add(resource2);
|
||||||
|
assertThat(resources).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resourcesWithDifferentInputPathsAreEqual() {
|
||||||
|
Resource resource1 = new ClassPathResource("org/springframework/core/io/Resource.class", getClass().getClassLoader());
|
||||||
|
ClassPathResource resource2 = new ClassPathResource("org/springframework/core/../core/io/./Resource.class", getClass().getClassLoader());
|
||||||
|
assertThat(resource2).isEqualTo(resource1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void relativeResourcesAreEqual() throws Exception {
|
||||||
|
Resource resource = new ClassPathResource("dir/");
|
||||||
|
Resource relative = resource.createRelative("subdir");
|
||||||
|
assertThat(relative).isEqualTo(new ClassPathResource("dir/subdir"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class GetInputStream {
|
class GetInputStream {
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import okhttp3.mockwebserver.Dispatcher;
|
import okhttp3.mockwebserver.Dispatcher;
|
||||||
@@ -205,40 +204,6 @@ class ResourceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nested
|
|
||||||
class ClassPathResourceTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void equalsAndHashCode() {
|
|
||||||
Resource resource = new ClassPathResource("org/springframework/core/io/Resource.class");
|
|
||||||
Resource resource2 = new ClassPathResource("org/springframework/core/../core/io/./Resource.class");
|
|
||||||
Resource resource3 = new ClassPathResource("org/springframework/core/").createRelative("../core/io/./Resource.class");
|
|
||||||
assertThat(resource2).isEqualTo(resource);
|
|
||||||
assertThat(resource3).isEqualTo(resource);
|
|
||||||
// Check whether equal/hashCode works in a HashSet.
|
|
||||||
HashSet<Resource> resources = new HashSet<>();
|
|
||||||
resources.add(resource);
|
|
||||||
resources.add(resource2);
|
|
||||||
assertThat(resources.size()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void resourcesWithDifferentPathsAreEqual() {
|
|
||||||
Resource resource = new ClassPathResource("org/springframework/core/io/Resource.class", getClass().getClassLoader());
|
|
||||||
ClassPathResource sameResource = new ClassPathResource("org/springframework/core/../core/io/./Resource.class", getClass().getClassLoader());
|
|
||||||
assertThat(sameResource).isEqualTo(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void relativeResourcesAreEqual() throws Exception {
|
|
||||||
Resource resource = new ClassPathResource("dir/");
|
|
||||||
Resource relative = resource.createRelative("subdir");
|
|
||||||
assertThat(relative).isEqualTo(new ClassPathResource("dir/subdir"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class FileSystemResourceTests {
|
class FileSystemResourceTests {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user