示例#1
0
 public Field findSingletonStaticPrivateInstanceField() {
   for (Field field : Earth.class.getDeclaredFields()) {
     if (field.getType() == Earth.class) {
       return field;
     }
   }
   return null;
 }
示例#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()));
 }
示例#3
0
 private void replaceEarth(String earthclass) throws Exception {
   System.setProperty("earthclass", earthclass);
   Field instance = findSingletonStaticPrivateInstanceField();
   instance.setAccessible(true);
   instance.set(null, null);
 }