InstanceFactory { public static <T> void setupInstanceAutomagic(final T t) { for (final Field field : t.getClass().getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(t.getClass())) { try { field.setAccessible(true); if (field.get(null) != null) { continue; } field.set(null, t); } catch (IllegalAccessException e) { ServerImplementation.getImplementation().getErrorDigest().digest(e); } } } }  static void setupInstance(final T t, final String fieldName); static void setupInstance(final T t); static void setupInstanceAutomagic(final T t);  }
@Test void setupInstanceAutomagic() { Assertions.assertNull(TestClass.instance); final TestClass testClass = new TestClass(); InstanceFactory.setupInstanceAutomagic(testClass); Assertions.assertEquals(testClass, TestClass.instance); }