-
Notifications
You must be signed in to change notification settings - Fork 198
ResourceUtils: fail with the file name when a resource is missing #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+77
−16
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,16 @@ | ||
| gradlew text eol=lf | ||
| # Normalize all text files to LF in the repository (checkout follows the platform). | ||
| * text=auto | ||
|
|
||
| # Scripts that must keep a specific line ending regardless of platform. | ||
| gradlew text eol=lf | ||
| *.sh text eol=lf | ||
| *.bat text eol=crlf | ||
| *.cmd text eol=crlf | ||
|
|
||
| # Binary assets — never touch line endings. | ||
| *.rar binary | ||
| *.jar binary | ||
| *.png binary | ||
| *.jpg binary | ||
| *.gif binary | ||
| *.ico binary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/io/nats/client/utils/ResourceUtilsTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| package io.nats.client.utils; | ||||||
|
|
||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import java.io.FileNotFoundException; | ||||||
|
|
||||||
| import static io.nats.client.utils.ResourceUtils.*; | ||||||
| import static org.junit.jupiter.api.Assertions.*; | ||||||
|
|
||||||
| public class ResourceUtilsTests { | ||||||
|
|
||||||
| private static final String MISSING = "ThisResourceDoesNotExist.json"; | ||||||
|
|
||||||
| @Test | ||||||
| public void testMissingResourceIdentifiesTheFile() { | ||||||
| assertMissing(assertThrows(RuntimeException.class, () -> dataAsString(MISSING))); | ||||||
| assertMissing(assertThrows(RuntimeException.class, () -> dataAsLines(MISSING))); | ||||||
| assertMissing(assertThrows(RuntimeException.class, () -> dataAsInputStream(MISSING))); | ||||||
| } | ||||||
|
|
||||||
| private void assertMissing(RuntimeException e) { | ||||||
| Throwable cause = e.getCause(); | ||||||
| assertInstanceOf(FileNotFoundException.class, cause); | ||||||
| assertTrue(cause.getMessage().contains(MISSING)); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testResourceStillLoads() { | ||||||
| assertTrue(dataAsString("StreamConfiguration.json").contains("retention")); | ||||||
| assertFalse(dataAsLines("StreamConfiguration.json").isEmpty()); | ||||||
| assertNotNull(dataAsInputStream("StreamConfiguration.json")); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or simply verify the method doesn't throw, without holding onto the stream. |
||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
"retention"string sentinel ties this test to the internal content ofStreamConfiguration.json. If the JSON is ever reorganised, this silently breaks. Asserting non-empty is sufficient to prove the load succeeded: