steveloughran commented on code in PR #7955:
URL: https://github.com/apache/hadoop/pull/7955#discussion_r2348675298
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java:
##########
@@ -345,6 +356,33 @@ public static void assertExceptionContains(String
expectedText,
}
}
+ /**
+ * Assert that an exception's <code>toString()</code> value
+ * matches the pattern.
+ * @param pattern regex pattern to match
+ * @param t thrown exception
+ * @param message any extra text for the string
+ * @throws AssertionError if the expected string is not found
+ */
+ public static void assertExceptionMatches(Pattern pattern,
+ Throwable t,
Review Comment:
rename to "caught"
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java:
##########
@@ -345,6 +356,33 @@ public static void assertExceptionContains(String
expectedText,
}
}
+ /**
+ * Assert that an exception's <code>toString()</code> value
+ * matches the pattern.
+ * @param pattern regex pattern to match
+ * @param t thrown exception
+ * @param message any extra text for the string
+ * @throws AssertionError if the expected string is not found
+ */
+ public static void assertExceptionMatches(Pattern pattern,
+ Throwable t,
+ String message) {
+ assertNotNull(t, E_NULL_THROWABLE);
+ String msg = t.toString();
+ if (msg == null) {
+ throw new AssertionError(E_NULL_THROWABLE_STRING, t);
+ }
+ if (pattern != null && !pattern.matcher(msg).matches()) {
Review Comment:
if a null pattern is passed in this test does nearly nothing. is that
appropriate? I'd rather it failed with an error about a null pattern passed
down, with that caught exception included in the chain just in case it is
useful.
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java:
##########
@@ -345,6 +356,33 @@ public static void assertExceptionContains(String
expectedText,
}
}
+ /**
+ * Assert that an exception's <code>toString()</code> value
+ * matches the pattern.
+ * @param pattern regex pattern to match
+ * @param t thrown exception
+ * @param message any extra text for the string
+ * @throws AssertionError if the expected string is not found
+ */
+ public static void assertExceptionMatches(Pattern pattern,
+ Throwable t,
+ String message) {
+ assertNotNull(t, E_NULL_THROWABLE);
+ String msg = t.toString();
+ if (msg == null) {
+ throw new AssertionError(E_NULL_THROWABLE_STRING, t);
+ }
+ if (pattern != null && !pattern.matcher(msg).matches()) {
+ String prefix = org.apache.commons.lang3.StringUtils.isEmpty(message)
Review Comment:
our own StringUtils.hasLength(message) does this. silly name but at least
unique.
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java:
##########
@@ -345,6 +356,33 @@ public static void assertExceptionContains(String
expectedText,
}
}
+ /**
+ * Assert that an exception's <code>toString()</code> value
+ * matches the pattern.
+ * @param pattern regex pattern to match
+ * @param t thrown exception
+ * @param message any extra text for the string
+ * @throws AssertionError if the expected string is not found
+ */
+ public static void assertExceptionMatches(Pattern pattern,
+ Throwable t,
+ String message) {
+ assertNotNull(t, E_NULL_THROWABLE);
+ String msg = t.toString();
Review Comment:
rename to caughtString; as msg means "message" to me, and it isn't as the
code doesn't use getMessage(). (which I'm happy with not using)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]