Ejemplo n.º 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()));
 }
Ejemplo n.º 2
0
 @Test
 public void checkThatSingletonContainsStaticPrivateInstanceField() {
   Field field = findSingletonStaticPrivateInstanceField();
   assertNotNull("No static private instance field found.", field);
   assertTrue(
       "Field pointing to the Earth instance should be static",
       Modifier.isStatic(field.getModifiers()));
   assertTrue(
       "Field pointing to the Earth instance should be private",
       Modifier.isPrivate(field.getModifiers()));
 }
Ejemplo n.º 3
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.
 }