コード例 #1
0
 @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()));
 }
コード例 #2
0
 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.
 }