Skip to content

Instantly share code, notes, and snippets.

@tadams
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadams/3b6f53703a828d26c7e0 to your computer and use it in GitHub Desktop.
Save tadams/3b6f53703a828d26c7e0 to your computer and use it in GitHub Desktop.
Negative Logic Example
public List<Class> buildClassHierarchy(Class cls) {
List<Class> classHierarchy = new ArrayList<>();
while (!Object.class.equals(cls) && cls != null) {
classHierarchy.add(cls);
cls = cls.getSuperclass();
}
return classHierarchy;
}
...
@Test
public void shouldReturnClassHiearchy() {
List<Class> classHierarchy = logic.buildClassHierarchy(MyMap.class);
assertThat(classHierarchy).contains(MyMap.class, HashMap.class, AbstractMap.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment