ClassUtil { private static void getAllInterfaces(final Class<?> cls, final Set<Class<?>> interfacesFound) { if (cls == null) { return; } for (var i : cls.getInterfaces()) { if (interfacesFound.add(i)) { getAllInterfaces(i, interfacesFound); } } getAllInterfaces(cls.getSuperclass(), interfacesFound); } private  ClassUtil(); static Stream<Class<?>> getAllInterfaces(final Class<?> original);  }
@Test void getInterfacesTest() { Stream<Class<?>> foundInterfaces = ClassUtil.getAllInterfaces(ArrayList.class); assertThat(foundInterfaces) .containsExactly(List.class, Collection.class, Iterable.class, RandomAccess.class, Cloneable.class, Serializable.class); }
@Test void getInterfacesNullTest() { Stream<Class<?>> foundInterfaces = ClassUtil.getAllInterfaces(null); assertThat(foundInterfaces).isEmpty(); }