@Test public void checkThatOtherMethodsAreNonStatic() throws NoSuchMethodException { Method spin = Earth.class.getDeclaredMethod("spin"); assertFalse("Method spin() should not be static", Modifier.isStatic(spin.getModifiers())); Method warmUp = Earth.class.getDeclaredMethod("warmUp"); assertFalse("Method warmUp() should not be static", Modifier.isStatic(warmUp.getModifiers())); }
private Method findPublicVoidMethod(Class<?> aClass, String methodName) { for (Method method : aClass.getDeclaredMethods()) { if (isPublic(method.getModifiers()) && method.getReturnType() == void.class && methodName.equals(method.getName())) { return method; } } return null; }
private Method checkThatSingletonContainsStaticInstanceAccessorMethod(Class clazz) { for (Method method : clazz.getDeclaredMethods()) { if (method.getReturnType() == clazz && method.getParameterTypes().length == 0) { assertTrue( "Method returning the Earth instance should be static", Modifier.isStatic(method.getModifiers())); return method; } } fail("No static accessor method found."); return null; // will never be called. }