arturobernalg commented on a change in pull request #121:
URL: https://github.com/apache/commons-geometry/pull/121#discussion_r544599521
##########
File path:
commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTestUtils.java
##########
@@ -88,23 +70,15 @@ public static void assertThrows(final Runnable r, final
Class<?> exceptionType,
* @param exceptionType the expected exception type
* @param pattern regex pattern to match; ignored if null
*/
- public static void assertThrows(final Runnable r, final Class<?>
exceptionType, final Pattern pattern) {
- try {
- r.run();
- Assertions.fail("Operation should have thrown an exception");
- } catch (final Exception exc) {
- final Class<?> actualType = exc.getClass();
-
- Assertions.assertTrue(exceptionType.isAssignableFrom(actualType),
- "Expected exception of type " + exceptionType.getName() +
" but was " + actualType.getName());
-
- if (pattern != null) {
- final String message = exc.getMessage();
-
- final String err = "Expected exception message to match /" +
pattern + "/ but was [" + message + "]";
- Assertions.assertTrue(pattern.matcher(message).matches(), err);
- }
- }
+ public static <T extends Throwable> void assertThrowsWithMessage(final
Runnable r, final Class<T> exceptionType, final Pattern pattern) {
+ final Throwable exc = Assertions.assertThrows(exceptionType, r::run);
+ Assertions.assertNotNull(pattern);
+ final Class<?> actualType = exc.getClass();
+ Assertions.assertTrue(exceptionType.isAssignableFrom(actualType),
Review comment:
changed
##########
File path:
commons-geometry-core/src/test/java/org/apache/commons/geometry/core/GeometryTestUtils.java
##########
@@ -88,23 +70,15 @@ public static void assertThrows(final Runnable r, final
Class<?> exceptionType,
* @param exceptionType the expected exception type
* @param pattern regex pattern to match; ignored if null
*/
- public static void assertThrows(final Runnable r, final Class<?>
exceptionType, final Pattern pattern) {
- try {
- r.run();
- Assertions.fail("Operation should have thrown an exception");
- } catch (final Exception exc) {
- final Class<?> actualType = exc.getClass();
-
- Assertions.assertTrue(exceptionType.isAssignableFrom(actualType),
- "Expected exception of type " + exceptionType.getName() +
" but was " + actualType.getName());
-
- if (pattern != null) {
- final String message = exc.getMessage();
-
- final String err = "Expected exception message to match /" +
pattern + "/ but was [" + message + "]";
- Assertions.assertTrue(pattern.matcher(message).matches(), err);
- }
- }
+ public static <T extends Throwable> void assertThrowsWithMessage(final
Runnable r, final Class<T> exceptionType, final Pattern pattern) {
+ final Throwable exc = Assertions.assertThrows(exceptionType, r::run);
+ Assertions.assertNotNull(pattern);
+ final Class<?> actualType = exc.getClass();
+ Assertions.assertTrue(exceptionType.isAssignableFrom(actualType),
+ "Expected exception of type " + exceptionType.getName() + "
but was " + actualType.getName());
+ final String message = exc.getMessage();
+ final String err = "Expected exception message to match /" + pattern +
"/ but was [" + message + "]";
+ Assertions.assertTrue(pattern.matcher(message).matches(), err);
Review comment:
changed
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]