/** * Return the set of methods for this type. The default implementation returns the * result of {@link Class#getMethods()} for the given {@code type}, but subclasses * may override in order to alter the results, e.g. specifying static methods * declared elsewhere. * @param type the class for which to return the methods * @since 3.1.1 */ protected Method[] getMethods(Class<?> type) { return type.getMethods(); }
/** * Return class methods ordered with non-bridge methods appearing higher. */ private Method[] getSortedMethods(Class<?> clazz) { return this.sortedMethodsCache.computeIfAbsent(clazz, key -> { Method[] methods = key.getMethods(); Arrays.sort(methods, (o1, o2) -> (o1.isBridge() == o2.isBridge() ? 0 : (o1.isBridge() ? 1 : -1))); return methods; }); }
/** Returns the most concrete public methods from {@code type}. */ private static Method[] getMostConcreteMethods(Class<?> type) { Method[] methods = type.getMethods(); for (int i = 0; i < methods.length; i++) { try { methods[i] = type.getMethod(methods[i].getName(), methods[i].getParameterTypes()); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } } return methods; }
private static Set<Method> findInterruptibleMethods(Class<?> interfaceType) { Set<Method> set = Sets.newHashSet(); for (Method m : interfaceType.getMethods()) { if (declaresInterruptedEx(m)) { set.add(m); } } return set; }
/** * Return whether the given bean class declares or inherits any non-void * returning bean property or indexed property setter methods. */ private boolean supports(Class<?> beanClass) { for (Method method : beanClass.getMethods()) { if (ExtendedBeanInfo.isCandidateWriteMethod(method)) { return true; } } return false; }
@Nullable private Method findDestroyMethod(String name) { return (this.nonPublicAccessAllowed ? BeanUtils.findMethodWithMinimalParameters(this.bean.getClass(), name) : BeanUtils.findMethodWithMinimalParameters(this.bean.getClass().getMethods(), name)); }
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) { Method[] methods = targetType.getMethods(); for (Method m : methods) { if (m.getName().equals(name) && m.getReturnType().equals(returnType)) { return m; } } return null; }
private static Method getMethodForReturnType(Class<?> returnType) { return Arrays.stream(TestBean.class.getMethods()) .filter(method -> method.getReturnType().equals(returnType)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unique return type not found: " + returnType)); }
static void scan(Class<?> clazz) { for (Method m : clazz.getMethods()) { if (m.getDeclaringClass() == clazz) { if ((m.getModifiers() & Modifier.STATIC) == 0) { if ((m.getModifiers() & (Modifier.PUBLIC | Modifier.FINAL)) == Modifier.PUBLIC) { fail("Not final: " + m); } } } } }
private static void doTestMocking(RateLimiter mock) throws Exception { for (Method method : RateLimiter.class.getMethods()) { if (!isStatic(method.getModifiers()) && !NOT_WORKING_ON_MOCKS.contains(method.getName()) && !method.getDeclaringClass().equals(Object.class)) { method.invoke(mock, arbitraryParameters(method)); } } }
@GwtIncompatible // reflection public void testAsMapBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("asMap") && m.getReturnType().equals(SortedMap.class)) { return; } } }
public void testReentrantReadWriteLock_implDoesNotExposeShadowedLocks() { assertEquals( "Unexpected number of public methods in ReentrantReadWriteLock. " + "The correctness of CycleDetectingReentrantReadWriteLock depends on " + "the fact that the shadowed ReadLock and WriteLock are never used or " + "exposed by the superclass implementation. If the implementation has " + "changed, the code must be re-inspected to ensure that the " + "assumption is still valid.", 24, ReentrantReadWriteLock.class.getMethods().length); }
protected Method getMethod(String name) { // Assumes no overloading of test methods... Method[] candidates = getClass().getMethods(); for (Method candidate : candidates) { if (candidate.getName().equals(name)) { return candidate; } } fail("Bad test specification, no method '" + name + "' found in test class"); return null; }
@Before public void setup() throws NoSuchMethodException { getAge = TestBean.class.getMethod("getAge"); // Assumes no overloading for (Method method : HasGeneric.class.getMethods()) { methodsOnHasGeneric.put(method.getName(), method); } }
@GwtIncompatible // reflection public void testKeySetBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("keySet") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); }
@GwtIncompatible // reflection public void testGetBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("get") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); } }
@GwtIncompatible // reflection @AndroidIncompatible // Reflection bug, or actual binary compatibility problem? public void testElementSetBridgeMethods() { for (Method m : TreeMultiset.class.getMethods()) { if (m.getName().equals("elementSet") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); } }
@Test public void testOnAllMethods() throws Exception { Method[] methods = StringList.class.getMethods(); for (Method method : methods) { assertNotNull(BridgeMethodResolver.findBridgedMethod(method)); } }
@Before public void setUp() throws Exception { this.comparator = new AspectJPrecedenceComparator(); this.anyOldMethod = getClass().getMethods()[0]; this.anyOldPointcut = new AspectJExpressionPointcut(); this.anyOldPointcut.setExpression("execution(* *(..))"); }
public static TestSuite suite() { TestSuite suite = new TestSuite(); Method[] methods = Monitor.class.getMethods(); sortMethods(methods); for (Method method : methods) { if (isAnyEnter(method) || isWaitFor(method)) { validateMethod(method); addTests(suite, method); } } assertEquals(548, suite.testCount()); return suite; }