/** Returns any method exactly matching the given signature, including privates and on parent classes. */ public static Maybe<Method> findMethodMaybe(Class<?> clazz, String name, Class<?>... parameterTypes) { if (clazz == null || name == null) return Maybe.absentNoTrace("class or name is null"); Iterable<Method> result = findMethods(false, clazz, name, parameterTypes); if (!result.iterator().hasNext()) return Maybe.absentNoTrace("no methods matching "+clazz.getName()+"."+name+"("+Arrays.asList(parameterTypes)+")"); return Maybe.of(result.iterator().next()); } /** Returns all methods compatible with the given argument types, including privates and on parent classes and where the method takes a supertype. */
@Test public void testMaybeAbsentMessageNoTraceDoesNotIncludeSource() { Maybe<Object> m = Maybe.absentNoTrace("nope"); Assert.assertFalse(m.isPresent()); Exception e = assertGetFailsContaining(m, "nope"); Assert.assertTrue(containsGetExplicitMethod(e), "Outer trace should be in explicit method"); Assert.assertFalse(containsMaybeMethod(e, "absentNoTrace"), "Outer trace should not be from 'absentNoTrace'"); Assert.assertNull(e.getCause()); }