Browse Source

Remove duplicate ClassPathResourceTests class

pull/29282/head
Sam Brannen 2 years ago
parent
commit
084d7d1bdc
  1. 38
      spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java
  2. 35
      spring-core/src/test/java/org/springframework/core/io/ResourceTests.java

38
spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java

@ -22,6 +22,7 @@ import java.io.FileOutputStream; @@ -22,6 +22,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -50,6 +51,43 @@ class ClassPathResourceTests { @@ -50,6 +51,43 @@ class ClassPathResourceTests {
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
class GetInputStream {

35
spring-core/src/test/java/org/springframework/core/io/ResourceTests.java

@ -30,7 +30,6 @@ import java.nio.ByteBuffer; @@ -30,7 +30,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.stream.Stream;
import okhttp3.mockwebserver.Dispatcher;
@ -205,40 +204,6 @@ class ResourceTests { @@ -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
class FileSystemResourceTests {

Loading…
Cancel
Save