CallbackInstantiator { public static <T> T getObjectOfType(String classOrMethod, Class<T> expectedClazz) { T object; try { object = getObjectOfTypeFromClassName(classOrMethod, expectedClazz); } catch (Exception ignore) { object = getObjectOfTypeFromFactoryMethod(classOrMethod); } return object; }  static T getObjectOfTypeFromClassName(String className, Class<T> expectedClazz); static SecurityManager getSecurityManager(Properties properties); static PostProcessor getPostProcessor(Properties properties); static T getObjectOfType(String classOrMethod, Class<T> expectedClazz);  }
@Test public void testGetObjectFromConstructor() { String string = CallbackInstantiator.getObjectOfType(String.class.getName(), String.class); assertThat(string).isNotNull().isEqualTo(""); CharSequence charSequence = CallbackInstantiator.getObjectOfType(String.class.getName(), CharSequence.class); assertThat(charSequence).isNotNull().isEqualTo(""); assertThatThrownBy( () -> CallbackInstantiator.getObjectOfType("com.abc.testString", String.class)) .isInstanceOf(GemFireSecurityException.class); assertThatThrownBy( () -> CallbackInstantiator.getObjectOfType(String.class.getName(), Boolean.class)) .isInstanceOf(GemFireSecurityException.class); assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType("", String.class)) .isInstanceOf(GemFireSecurityException.class); assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType(null, String.class)) .isInstanceOf(GemFireSecurityException.class); assertThatThrownBy(() -> CallbackInstantiator.getObjectOfType(" ", String.class)) .isInstanceOf(GemFireSecurityException.class); }
@Test public void testGetObjectFromFactoryMethod() { String string = CallbackInstantiator.getObjectOfType(Factories.class.getName() + ".getString", String.class); assertThat(string).isNotNull().isEqualTo(STRING); CharSequence charSequence = CallbackInstantiator .getObjectOfType(Factories.class.getName() + ".getString", String.class); assertThat(charSequence).isNotNull().isEqualTo(STRING); assertThatThrownBy(() -> CallbackInstantiator .getObjectOfType(Factories.class.getName() + ".getStringNonStatic", String.class)) .isInstanceOf(GemFireSecurityException.class); assertThatThrownBy(() -> CallbackInstantiator .getObjectOfType(Factories.class.getName() + ".getNullString", String.class)) .isInstanceOf(GemFireSecurityException.class); }