### Question:
ImageComparisonMatchers { @Factory public static Matcher<Object> isApproved() throws IOException { final StackTraceElement trace = StackUtils .getCallingTestMethodStackTraceElement(); final String methodName = trace.getMethodName(); final String className = getClassName(trace); final Class<?> clazz = getClassObject(trace); return looksLike(String.format("%s.%s.png", className, methodName), clazz); }  @SuppressWarnings("UnusedDeclaration") @Factory static Matcher<Object> looksLike(final String string); @Factory static Matcher<Object> looksLike(final String string,
                                            final Class<?> callingClass); @Factory static Matcher<Object> isApproved(); @SuppressWarnings("UnusedDeclaration") @Factory static Matcher<String> matchesFile(final String filename);  }### Answer:
@Test public void isApproved_withNullActual() throws Exception { matcher = ImageComparisonMatchers.isApproved(); try { matcher.matches(null); fail("Expected RuntimeException"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("Don't know how to make an image of <null>")); } }
@Test public void isApproved_withActualThatCantBeMadeIntoAnImage() throws Exception { matcher = ImageComparisonMatchers.isApproved(); try { matcher.matches(new SomeObject()); fail("Expected RuntimeException"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("Don't know how to make an image of <{{ some object }}>")); } }
@Test public void isApproved_whenApprovalImageDoesNotExist() throws Exception { matcher = ImageComparisonMatchers.isApproved(); final BufferedImage image = new BufferedImage(1, 1, TYPE_INT_RGB); assertThat(matcher, doesNotMatch(image).withDescription("approval image " + "ImageComparisonMatchersTest.isApproved_whenApprovalImageDoesNotExist.png doesn't exist " + "-- expected to find it in net.avh4.util.imagecomparison.hamcrest")); }
@Test public void isApproved_withMatchingImage() throws Exception { matcher = ImageComparisonMatchers.isApproved(); final BufferedImage image = ImageIO.read(getClass().getResource( "/net/avh4/util/imagecomparison/hamcrest/ImageComparisonMatchersTest.isApproved_withMatchingImage.png")); assertThat(matcher, not(doesNotMatch(image))); }