junit5
junit5 copied to clipboard
Expose more functionality from package org.junit.platform.commons.util
I have some assertions and extensions. These use some of the functionality from package org.junit.platform.commons.util. Now I'm trying to upgrade to Java 11, but that package is only exported to a select set of JUnit modules. That makes it hard to achieve some functionality. I have switched to using classes like AnnotationSupport instead of AnnotationUtils and ReflectionSupport instead of ReflectionUtils, but not all is exposed through other classes.
Functionality I'm still using from org.junit.platform.commons.util:
ReflectionUtils.parseFullyQualifiedMethodNameandReflectionUtils.getRequiredMethodfor functionality similar to@MethodSource.- There is
ReflectionSupport.findMethod, but perhaps adding these two methods could also be done.
- There is
ExceptionUtils.throwAsUncheckedExceptionfor simplified error handling.- Note that this method is part of documentation, for example see
Assumptions.assumingThatorThrowableCollector.assertEmpty.
- Note that this method is part of documentation, for example see
The methods from ReflectionUtils are easy enough to achieve - just copy them to ReflectionSupport. That's also done for findMethod and other methods. For ExceptionUtils, perhaps a class ExceptionSupport can be added in org.junit.platform.commons.support.
ReflectionUtils.parseFullyQualifiedMethodName
I'm in favor of making that one public/supported as well as ReflectionUtils.getFullyQualifiedMethodName.
ReflectionUtils.getRequiredMethod
That one is really just a convenience for ReflectionSupport.findMethod. So I'm not convinced it warrants being public/supported, but on the other hand it's not an issue to introduce it in terms of maintenance.
ExceptionUtils.throwAsUncheckedExceptionfor simplified error handling.
We intentionally did not make that a supported feature, because we don't want to encourage its use. We only introduced that support within the framework itself out of necessity.
Though I suppose we could consider making it public/supported.
I get the idea of not exporting org.junit.platform.commons.util. The package is meant for use by the JUnit framework itself. The only thing is, it's full with utility classes and methods that are very useful for creating extensions as well. I'm thinking not just these cases, but Preconditions as well. Exposing that functionality through *Support classes is an option, but maybe a separate module that needs to be explicitly required in module descriptors is a better option. That may be difficult if classes from the util package use classes from other packages - you'll get circular dependencies.
FYI, I have been working on my own method lookup, to remove the need for parseFullyQualifiedMethodName. I did this because I needed lookups that supported different possible parameter type combinations, so I had to write this class anyway. I just had to replace the use of parseFullyQualifiedMethodName. I've made the formatting rules stricter, by enforcing that each of the parts matches only Java identifier parts.
You can take a look at my code at https://github.com/robtimus/junit-support/blob/master/src/main/java/com/github/robtimus/junit/support/extension/MethodLookup.java