Remove locale-dependent string checking

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
This commit is contained in:
Jason Tedor 2019-05-31 12:06:52 -04:00
parent f22dcfb9da
commit 61c6a26b31
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 9 additions and 1 deletions

View File

@ -171,7 +171,15 @@ public class PluginsServiceTests extends ESTestCase {
if (Constants.WINDOWS) { if (Constants.WINDOWS) {
assertThat(e.getCause(), instanceOf(NoSuchFileException.class)); assertThat(e.getCause(), instanceOf(NoSuchFileException.class));
} else { } 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)));
} }
} }
} }