InMemoryRootDirectory implements AggregateRootDirectory { @Override public Optional<? extends AggregatePartRepository<?, ?, ?>> findPart(Class<? extends AggregateRoot<?>> rootClass, Class<? extends EntityState> partStateClass) { Set<AggregatePartRepository<?, ?, ?>> parts = repositories.get(rootClass); if (parts.isEmpty()) { return Optional.empty(); } else { TypeUrl targetType = TypeUrl.of(partStateClass); Optional<AggregatePartRepository<?, ?, ?>> repository = parts .stream() .filter(repo -> repo.entityStateType().equals(targetType)) .findAny(); return repository; } }  @Override void register(AggregatePartRepository<?, ?, ?> repository); @Override Optional<? extends AggregatePartRepository<?, ?, ?>> findPart(Class<? extends AggregateRoot<?>> rootClass,
             Class<? extends EntityState> partStateClass);  }
@Test @DisplayName("not find a non-registered repository") void notFindRepository() { Optional<? extends AggregatePartRepository<?, ?, ?>> found = directory.findPart(TaskRoot.class, AggTask.class); OptionalSubject assertRepository = assertThat(found); assertRepository.isEmpty(); }