### Question:
RelationResolver { public static int calculateInheritanceDistance(Class<?> parent, Class<?> child) { if (!parent.isAssignableFrom(child)) { return -1; } if (parent.isInterface() || child.isInterface()) { throw new IllegalArgumentException(format("Parent/Child classes could not be interfaces: %s, %s", parent, child)); } int distance = 0; while (!parent.equals(child)) { distance++; child = child.getSuperclass(); } return distance; } private  RelationResolver(); static int calculateInheritanceDistance(Class<?> parent, Class<?> child);  }### Answer:
@Test public void calculateInheritanceDistanceUnassignable() { Class<?> parent = Error.class; Class<?> child = RuntimeException.class; int distance = RelationResolver.calculateInheritanceDistance(parent, child); assertThat(distance, is(-1)); }
@Test(expected = IllegalArgumentException.class) public void calculateInheritanceDistanceAssignableInterfaces() { Class<?> parent = Advice.class; Class<?> child = MethodInterceptor.class; RelationResolver.calculateInheritanceDistance(parent, child); }
@Test public void calculateInheritanceDistanceObjects() { Class<?> parent = Object.class; Class<?> child = Object.class; int distance = RelationResolver.calculateInheritanceDistance(parent, child); assertThat(distance, is(0)); }
@Test public void calculateInheritanceDistanceEquals() { Class<?> parent = String.class; Class<?> child = String.class; int distance = RelationResolver.calculateInheritanceDistance(parent, child); assertThat(distance, is(0)); }
@Test public void calculateInheritanceDistance() { Class<?> parent = Throwable.class; Class<?> child = ArrayIndexOutOfBoundsException.class; int distance = RelationResolver.calculateInheritanceDistance(parent, child); assertThat(distance, is(4)); }
@Test public void calculateInheritanceDistanceReverse() { Class<?> parent = ArrayIndexOutOfBoundsException.class; Class<?> child = Throwable.class; int distance = RelationResolver.calculateInheritanceDistance(parent, child); assertThat(distance, is(-1)); }