From 084d7d1bdc8ef24b7c045efcfb67ea09b0aedd85 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 5 Oct 2022 14:50:27 +0200 Subject: [PATCH] Remove duplicate ClassPathResourceTests class --- .../core/io/ClassPathResourceTests.java | 38 +++++++++++++++++++ .../core/io/ResourceTests.java | 35 ----------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java index 21179de877..63fcd6fbf4 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java @@ -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 { 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 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 { diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index 7b35699d7f..b0ce104fef 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -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 { } } - - @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 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 {