### Question:
SystemPropertyReporter implements Reporter { static SystemPropertyReporter getInstanceForClassnameOrFactoryMethod(String name) { return new SystemPropertyReporter(name); } private  SystemPropertyReporter(String classOrFactoryMethod); Reporter getReporter(); static Reporter getInstance(String propertyName); @Override void notTheSame(byte[] oldValue, File fileForVerification, byte[] newValue, File fileForApproval); @Override void approveNew(byte[] value, File fileForApproval, File fileForVerification); @Override boolean canApprove(File fileForApproval);  }### Answer:
@Test(expected = NoSuchMethodException.class) public void shouldReportIfClassDoesntExist() throws Throwable { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod(ReporterWithNotDefaultCtor.class.getName()); } catch (AssertionError error) { throw error.getCause(); } }
@Test public void shouldProperlyInstantiateOtherClassesButThrowOnCasting() { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod(ReflectiveBeanConverter.class.getName()); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { Assert.assertThat(error.getMessage(), CoreMatchers.containsString("but it isn't a reporter")); } }
@Test(expected = ClassNotFoundException.class) public void shouldThrowIfTheClassFromTheMethodDefinitionDoesntExist() throws Throwable { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod("com.github.approval.NonEistingClass.gvim"); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { throw error.getCause(); } }
@Test(expected = NoSuchMethodException.class) public void shouldThrowIfTheFactoryMethodAcceptsParameters() throws Throwable { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod(this.getClass().getName() + ".failingMethod"); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { throw error.getCause(); } }
@Test public void shouldThrowIfReturnedInstanceFromMethodIsNotReporter() { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod(this.getClass().getName() + ".failingMethodBadInstance"); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { Assert.assertThat(error.getMessage(), CoreMatchers.containsString("is not a reporter")); } }
@Test public void shouldThrowProperExceptionOnReallyReallyBadInputThatBreaksSplit() { try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod("ClassThatDoesntExist"); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { Assert.assertThat(error.getMessage(), CoreMatchers.containsString("Couldn't instantiate class ")); } try { SystemPropertyReporter.getInstanceForClassnameOrFactoryMethod(ReflectiveBeanConverter.class.getName() + "."); Assert.fail("Should throw an exception!"); } catch (AssertionError error) { Assert.assertThat(error.getMessage(), CoreMatchers.containsString("Couldn't instantiate class ")); } }