From 67452d16611674a29631a325ad6ed14c6a0e932b Mon Sep 17 00:00:00 2001 From: Alberto Scotto Date: Sun, 19 Apr 2020 15:34:04 +0200 Subject: [PATCH] Cleanup the subclasses of FeatureMatcher which are currently try-catch-ing --- hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java | 2 +- hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java b/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java index b781295e..6bad17d2 100644 --- a/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java @@ -33,7 +33,7 @@ public FeatureMatcher(Matcher subMatcher, String featureDescription, * @param actual the target object * @return the feature to be matched */ - protected abstract U featureValueOf(T actual); + protected abstract U featureValueOf(T actual) throws Exception; @Override protected boolean matchesSafely(T actual, Description mismatch) { diff --git a/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java b/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java index 0b76fb14..9ea93574 100644 --- a/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java +++ b/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java @@ -50,12 +50,8 @@ public static Matcher aFileNamed(final Matcher expected) { public static Matcher aFileWithCanonicalPath(final Matcher expected) { return new FeatureMatcher(expected, "A file with canonical path", "path") { - @Override protected String featureValueOf(File actual) { - try { - return actual.getCanonicalPath(); - } catch (IOException e) { - return "Exception: " + e.getMessage(); - } + @Override protected String featureValueOf(File actual) throws IOException { + return actual.getCanonicalPath(); } }; }