Skip to content

Commit

Permalink
Remove locale-dependent string checking
Browse files Browse the repository at this point in the history
We were checking if an exception was caused by a specific reason "Not a
directory". Alas, this reason is locale-dependent and can fail on
systems that are not set to en_US.UTF-8. This commit addresses this by
deriving what the locale-dependent error message would be and using that
for comparison with the actual exception thrown.

Relates #41689
  • Loading branch information
jasontedor committed May 31, 2019
1 parent f22dcfb commit 61c6a26
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ public void testDesktopServicesStoreFiles() throws IOException {
if (Constants.WINDOWS) {
assertThat(e.getCause(), instanceOf(NoSuchFileException.class));
} else {
assertThat(e.getCause(), hasToString(containsString("Not a directory")));
// force a "Not a directory" exception to be thrown so that we can extract the locale-dependent message
final String expected;
try (InputStream ignored = Files.newInputStream(desktopServicesStore.resolve("not-a-directory"))) {
throw new AssertionError();
} catch (final FileSystemException inner) {
// locale-dependent translation of "Not a directory"
expected = inner.getReason();
}
assertThat(e.getCause(), hasToString(containsString(expected)));
}
}
}
Expand Down

0 comments on commit 61c6a26

Please sign in to comment.