You could catch the exception from verify and rethrow it as TestAbortedException:
try {
verify(mockObject).doSomething();
} catch (final MockitoAssertionError ex) {
throw new TestAbortedException("Method doSomething not called", ex);
}
(Although I don't know why you'd want to not fail the test in this case. If the method call is not required, don't verify/assert it at all?)
Extract a utility method to make this logic reusable:
class VerificationAssumptions {
private VerificationAssumptions() {}
static void assumeVerify(final String message, final Runnable verification) {
try {
verification.run();
} catch (final MockitoAssertionError ex) {
throw new TestAbortedException(message, ex);
}
}
}
and then use:
VerificationAssumptions.assumeVerify(
"Method doSomething not called",
() -> verify(mockObject).doSomething());
(you might be able to implement a nicer API, such as assumeVerify(mockObject).doSomething(), but I'll leave this to the reader ;))
verify(mock, never()).should()for, or perhaps evenverifyNoInteractions(mock)orverifyNoMoreInteractions(mock).try { verify(mock, atLeastOnce()).should(); } catch (AssertionError _) { assumeTrue(false, "should() hasn't been invoked"); }. I'm guessing the error to catch, you may need to change it.