### Question:
ErrorLogResolver { public ErrorLog resolve(Set<ErrorLog> errorLogs, Class<?> causeClass) { int minDistance = -1; ErrorLog result = null; for (ErrorLog errorLog : errorLogs) { if (noneMatchExclude(errorLog, causeClass)) { int distance = minInheritanceDistance(errorLog, causeClass); if (distance >= 0 && (minDistance < 0 || distance < minDistance)) { minDistance = distance; result = errorLog; } } } return result; } private  ErrorLogResolver(); static ErrorLogResolver getInstance(); ErrorLog resolve(Set<ErrorLog> errorLogs, Class<?> causeClass);  }### Answer:
@Test public void resolve() { ErrorLog aErrorLog = TestErrorLogFactory.newInstance( new Class<?>[]{NullPointerException.class, IndexOutOfBoundsException.class}, new Class<?>[]{StringIndexOutOfBoundsException.class}); Set<ErrorLog> errorLogs = singleton(aErrorLog); Class<?> causeClass = ArrayIndexOutOfBoundsException.class; ErrorLog errorLog = errorLogResolver.resolve(errorLogs, causeClass); assertThat(errorLog, is(aErrorLog)); }
@Test public void resolveExclude() { ErrorLog aErrorLog = TestErrorLogFactory.newInstance(new Class<?>[]{Throwable.class}, new Class<?>[]{RuntimeException.class}); Set<ErrorLog> errorLogs = singleton(aErrorLog); Class<?> causeClass = NullPointerException.class; ErrorLog errorLog = errorLogResolver.resolve(errorLogs, causeClass); assertThat(errorLog, nullValue()); }
@Test public void resolveNotFound() { ErrorLog aErrorLog = TestErrorLogFactory.newInstance(new Class<?>[]{Exception.class}, new Class<?>[]{RuntimeException.class}); Set<ErrorLog> errorLogs = singleton(aErrorLog); Class<?> causeClass = Throwable.class; ErrorLog errorLog = errorLogResolver.resolve(errorLogs, causeClass); assertThat(errorLog, nullValue()); }
@Test public void resolveMostSpecific() { ErrorLog aErrorLog = TestErrorLogFactory.newInstance( new Class<?>[]{NullPointerException.class, IndexOutOfBoundsException.class}, new Class<?>[]{StringIndexOutOfBoundsException.class}); ErrorLog bErrorLog = TestErrorLogFactory.newInstance( new Class<?>[]{ArrayIndexOutOfBoundsException.class}, new Class<?>[]{}); Set<ErrorLog> errorLogs = new LinkedHashSet<>(asList(aErrorLog, bErrorLog)); Class<?> causeClass = ArrayIndexOutOfBoundsException.class; ErrorLog errorLog = errorLogResolver.resolve(errorLogs, causeClass); assertThat(errorLog, is(bErrorLog)); }