### Question:
DependencyInjector { @SuppressWarnings("unchecked") public <T> T getInstanceOf(Class<? extends T> type) { if (isCustomInjectorDefined()) { return (T) customInjector.call(type); } else { try { return type.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Can't create instance of type " + type.getName() + ". Make sure that the class has a public no-arg constructor.", e); } } } DependencyInjector(); static DependencyInjector getInstance(); void setCustomInjector(Callback<Class<?>, Object> callback); @SuppressWarnings("unchecked") T getInstanceOf(Class<? extends T> type);  }### Answer:
@Test public void testGetInstanceOfExceptionBecauseOfPrivateConstructor() { try { ExampleWithPrivateConstructor instance = injector.getInstanceOf(ExampleWithPrivateConstructor.class); fail("There should be an IllegalAccessException"); } catch (RuntimeException e) { Assert.assertTrue(e.getCause() instanceof IllegalAccessException); } }
@Test public void testGetInstanceOfExceptionBecauseOfParameterizedConstructor() { try { ExampleWithParamsConstructor instance = injector.getInstanceOf(ExampleWithParamsConstructor.class); fail("There should be an InstantiationException"); } catch (RuntimeException e) { Assert.assertTrue(e.getCause() instanceof InstantiationException); } }