From 31a51cca4f1df9877e5d341ee7778c33e5c76729 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 30 Jun 2023 00:35:14 +0200 Subject: [PATCH] Support for getFilename() in ModuleResource See gh-28507 --- .../java/org/springframework/core/io/ModuleResource.java | 6 ++++++ .../org/springframework/core/io/ModuleResourceTests.java | 2 ++ 2 files changed, 8 insertions(+) diff --git a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java index 2953a995c548..6835abb1a880 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java @@ -92,6 +92,12 @@ public Resource createRelative(String relativePath) { return new ModuleResource(this.module, pathToUse); } + @Override + @Nullable + public String getFilename() { + return StringUtils.getFilename(this.path); + } + @Override public String getDescription() { return "module resource [" + this.path + "]" + diff --git a/spring-core/src/test/java/org/springframework/core/io/ModuleResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ModuleResourceTests.java index 150af1f1c223..acb15276fe1d 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ModuleResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ModuleResourceTests.java @@ -40,6 +40,7 @@ void existingResource() throws IOException { assertThat(mr.isReadable()).isTrue(); assertThat(mr.isOpen()).isFalse(); assertThat(mr.isFile()).isFalse(); + assertThat(mr.getFilename()).isEqualTo("Introspector.class"); assertThat(mr.getDescription()).contains(mr.getModule().getName()); assertThat(mr.getDescription()).contains(mr.getPath()); @@ -55,6 +56,7 @@ void nonExistingResource() { assertThat(mr.isReadable()).isFalse(); assertThat(mr.isOpen()).isFalse(); assertThat(mr.isFile()).isFalse(); + assertThat(mr.getFilename()).isEqualTo("Introspecter.class"); assertThat(mr.getDescription()).contains(mr.getModule().getName()); assertThat(mr.getDescription()).contains(mr.getPath());