### Question:
Injector { static <T> T instantiateTestSubject(Field f) { T testSubject; @SuppressWarnings("unchecked") Class<T> type = (Class<T>) f.getType(); if(type.isMemberClass() && !Modifier.isStatic(type.getModifiers())) { throw new AssertionError("TestSubject is an inner class. You need to instantiate '" + f.getName() + "' manually"); } Constructor<T> defaultConstructor; try { defaultConstructor = type.getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new AssertionError("TestSubject is null and has no default constructor. You need to instantiate '" + f.getName() + "' manually"); } defaultConstructor.setAccessible(true); try { testSubject = defaultConstructor.newInstance(); } catch (ReflectiveOperationException e) { throw new AssertionError("TestSubject is null and default constructor fails on invocation. You need to instantiate '" + f.getName() + "' manually", e); } return testSubject; }  static void injectMocks(Object host);  }### Answer:
@Test public void testInstantiateTestSubject_existingNoArg() { String actual = Injector.instantiateTestSubject(field("noArg")); assertEquals("", actual); }
@Test public void testInstantiateTestSubject_noNoArg() { AssertionError e = assertThrows(AssertionError.class, () -> Injector.instantiateTestSubject(field("noNoArg"))); assertEquals("TestSubject is null and has no default constructor. You need to instantiate 'noNoArg' manually", e.getMessage()); }
@Test public void testInstantiateTestSubject_noArgWithException() { AssertionError e = assertThrows(AssertionError.class, () -> Injector.instantiateTestSubject(field("throwingNoArgConstructor"))); assertEquals("TestSubject is null and default constructor fails on invocation. You need to instantiate 'throwingNoArgConstructor' manually", e.getMessage()); assertEquals(InvocationTargetException.class, e.getCause().getClass()); assertEquals("Test", e.getCause().getCause().getMessage()); }
@Test public void testInstantiateTestSubject_privateNoArg() { PrivateNoArgConstructor actual = Injector.instantiateTestSubject(field("privateNoArgConstructor")); assertNotNull(actual); }
@Test public void testInstantiateTestSubject_staticClass() { StaticClass actual = Injector.instantiateTestSubject(field("staticClass")); assertNotNull(actual); }
@Test public void testInstantiateTestSubject_innerClass() { AssertionError e = assertThrows(AssertionError.class, () -> Injector.instantiateTestSubject(field("innerClass"))); assertEquals("TestSubject is an inner class. You need to instantiate 'innerClass' manually", e.getMessage()); }