Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Mar 12, 2024
1 parent e5a69dc commit 723c94e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class ModuleResourceTests {

private static final String existingPath = "java/beans/Introspector.class";

private static final String nonExistingPath = "org/example/NonExistingClass.class";


Expand All @@ -48,20 +49,10 @@ void existingClassFileResource() throws IOException {
ModuleResource mr = new ModuleResource(Introspector.class.getModule(), existingPath);
assertExistingResource(mr);
assertThat(mr.getDescription()).startsWith("module resource").contains(mr.getModule().getName(), mr.getPath());
System.err.println(mr.getDescription());

assertThat(mr.getContentAsByteArray()).isEqualTo(cpr.getContentAsByteArray());
assertThat(mr.contentLength()).isEqualTo(cpr.contentLength());
}

private static void assertExistingResource(Resource resource) {
assertThat(resource.exists()).isTrue();
assertThat(resource.isReadable()).isTrue();
assertThat(resource.isOpen()).isFalse();
assertThat(resource.isFile()).isFalse();
assertThat(resource.getFilename()).isEqualTo("Introspector.class");
}

@Test
void nonExistingResource() {
ModuleResource mr = new ModuleResource(Introspector.class.getModule(), nonExistingPath);
Expand All @@ -81,6 +72,7 @@ void equalsAndHashCode() {
Resource resource1 = new ModuleResource(Introspector.class.getModule(), existingPath);
Resource resource2 = new ModuleResource(Introspector.class.getModule(), existingPath);
Resource resource3 = new ModuleResource(Introspector.class.getModule(), nonExistingPath);

assertThat(resource1).isEqualTo(resource1);
assertThat(resource1).isEqualTo(resource2);
assertThat(resource2).isEqualTo(resource1);
Expand All @@ -89,4 +81,13 @@ void equalsAndHashCode() {
assertThat(resource1).doesNotHaveSameHashCodeAs(resource3);
}


private static void assertExistingResource(Resource resource) {
assertThat(resource.exists()).isTrue();
assertThat(resource.isReadable()).isTrue();
assertThat(resource.isOpen()).isFalse();
assertThat(resource.isFile()).isFalse();
assertThat(resource.getFilename()).isEqualTo("Introspector.class");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -51,14 +51,14 @@
*/
class PathMatchingResourcePatternResolverTests {

private static final String[] CLASSES_IN_CORE_IO_SUPPORT = { "EncodedResource.class",
private static final String[] CLASSES_IN_CORE_IO_SUPPORT = {"EncodedResource.class",
"LocalizedResourceHelper.class", "PathMatchingResourcePatternResolver.class", "PropertiesLoaderSupport.class",
"PropertiesLoaderUtils.class", "ResourceArrayPropertyEditor.class", "ResourcePatternResolver.class",
"ResourcePatternUtils.class", "SpringFactoriesLoader.class" };
"ResourcePatternUtils.class", "SpringFactoriesLoader.class"};

private static final String[] TEST_CLASSES_IN_CORE_IO_SUPPORT = { "PathMatchingResourcePatternResolverTests.class" };
private static final String[] TEST_CLASSES_IN_CORE_IO_SUPPORT = {"PathMatchingResourcePatternResolverTests.class"};

private static final String[] CLASSES_IN_REACTOR_UTIL_ANNOTATION = { "NonNull.class", "NonNullApi.class", "Nullable.class" };
private static final String[] CLASSES_IN_REACTOR_UTIL_ANNOTATION = {"NonNull.class", "NonNullApi.class", "Nullable.class"};


private PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Expand Down Expand Up @@ -329,8 +329,8 @@ private void assertExactSubPaths(String pattern, String pathPrefix, String... su
}

private String getPath(Resource resource) {
// Tests fail if we use resouce.getURL().getPath(). They would also fail on Mac OS when
// using resouce.getURI().getPath() if the resource paths are not Unicode normalized.
// Tests fail if we use resource.getURL().getPath(). They would also fail on macOS when
// using resource.getURI().getPath() if the resource paths are not Unicode normalized.
//
// On the JVM, all tests should pass when using resouce.getFile().getPath(); however,
// we use FileSystemResource#getPath since this test class is sometimes run within a
Expand Down

0 comments on commit 723c94e

Please sign in to comment.