Skip to content

Commit

Permalink
Merge branch '6.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jun 29, 2023
2 parents e475151 + 0c39fff commit 7028de9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ public String getFilename() {
return null;
}

/**
* Lazily access the logger for debug logging in case of an exception.
*/
private void debug(Supplier<String> message, Throwable ex) {
Log logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug(message.get(), ex);
}
}


/**
* This implementation compares description strings.
Expand Down Expand Up @@ -249,11 +259,4 @@ public String toString() {
return getDescription();
}

private void debug(Supplier<String> message, Throwable ex) {
Log logger = LogFactory.getLog(getClass());
if (logger.isDebugEnabled()) {
logger.debug(message.get(), ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ private static String platformPath(String string) {
@Test
void nullPath() {
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((Path) null))
.withMessageContaining("Path must not be null");
.withMessageContaining("Path must not be null");
}

@Test
void nullPathString() {
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((String) null))
.withMessageContaining("Path must not be null");
.withMessageContaining("Path must not be null");
}

@Test
void nullUri() {
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((URI) null))
.withMessageContaining("URI must not be null");
.withMessageContaining("URI must not be null");
}

@Test
Expand Down Expand Up @@ -258,6 +258,17 @@ void directoryIsNotWritable() {
assertThat(resource.isWritable()).isFalse();
}

@Test
void equalsAndHashCode() {
Resource mr1 = new PathResource(TEST_FILE);
Resource mr2 = new PathResource(TEST_FILE);
Resource mr3 = new PathResource(TEST_DIR);
assertThat(mr1).isEqualTo(mr2);
assertThat(mr1).isNotEqualTo(mr3);
assertThat(mr1).hasSameHashCodeAs(mr2);
assertThat(mr1).doesNotHaveSameHashCodeAs(mr3);
}

@Test
void outputStream(@TempDir Path temporaryFolder) throws IOException {
PathResource resource = new PathResource(temporaryFolder.resolve("test"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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 @@ -57,7 +57,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem


/**
* Create a new ServletContextResource.
* Create a new {@code ServletContextResource} for the given path.
* <p>The Servlet spec requires that resource paths start with a slash,
* even if many containers accept paths without leading slash too.
* Consequently, the given path will be prepended with a slash if it
Expand Down Expand Up @@ -94,6 +94,7 @@ public final String getPath() {
return this.path;
}


/**
* This implementation checks {@code ServletContext.getResource}.
* @see jakarta.servlet.ServletContext#getResource(String)
Expand Down

0 comments on commit 7028de9

Please sign in to comment.