コード例 #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);
 }