DependencyGraphImpl implements DependencyGraph { @Override public Optional<DependencyNode> getIfPresent(Class<?> clazz) { for (final Map.Entry<Class<?>, DependencyNode>impl : nodes.entrySet()) { if (clazz.isAssignableFrom(impl.getKey())) { return Optional.of(impl.getValue()); } } return Optional.empty(); } DependencyGraphImpl(Function<Class<?>, InjectorProxy> proxyFunction); @Override DependencyNode get(Class<?> clazz); @Override DependencyNode getOrCreate(Class<?> clazz); @Override Optional<DependencyNode> getIfPresent(Class<?> clazz); @Override DependencyGraph inject(); @Override Stream<DependencyNode> nodes();  }
@Test void getIfPresent() { assertFalse(instance.getIfPresent(Foo.class).isPresent()); ; instance.getOrCreate(Foo.class); final Optional<DependencyNode> optionalNode = instance.getIfPresent(Foo.class); assertEquals(Foo.class, optionalNode.orElseThrow(NoSuchElementException::new).getRepresentedType()); }