MemoryMailRepositoryStore implements MailRepositoryStore, Startable { @Override public MailRepository select(MailRepositoryUrl mailRepositoryUrl) { return destinationToRepositoryAssociations.computeIfAbsent(mailRepositoryUrl, Throwing.function(this::createNewMailRepository).sneakyThrow()); } @Inject  MemoryMailRepositoryStore(MailRepositoryUrlStore urlStore, MailRepositoryLoader mailRepositoryLoader, MailRepositoryStoreConfiguration configuration); @Override Optional<Protocol> defaultProtocol(); void init(); @Override Stream<MailRepositoryUrl> getUrls(); @Override Optional<MailRepository> get(MailRepositoryUrl url); @Override Stream<MailRepository> getByPath(MailRepositoryPath path); @Override MailRepository select(MailRepositoryUrl mailRepositoryUrl);  }
@Test(expected = MailRepositoryStore.UnsupportedRepositoryStoreException.class) public void selectingANonRegisteredProtocolShouldFail() { repositoryStore.select(MailRepositoryUrl.from("proto: }
@Test public void selectingARegisteredProtocolShouldWork() { assertThat(repositoryStore.select(MEMORY1_REPO)) .isInstanceOf(MemoryMailRepository.class); }
@Test public void selectingTwiceARegisteredProtocolWithSameDestinationShouldReturnTheSameResult() { assertThat(repositoryStore.select(MEMORY1_REPO)) .isEqualTo(repositoryStore.select(MEMORY1_REPO)); }
@Test public void selectingTwiceARegisteredProtocolWithDifferentDestinationShouldReturnDifferentResults() { assertThat(repositoryStore.select(MEMORY1_REPO)) .isNotEqualTo(repositoryStore.select(MailRepositoryUrl.from("memory1: }
@Test public void getPathsShouldReturnUsedUrls() { MailRepositoryPath path1 = MailRepositoryPath.from("repo1"); MailRepositoryPath path2 = MailRepositoryPath.from("repo1"); MailRepositoryPath path3 = MailRepositoryPath.from("repo1"); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path1, "memory1")); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path2, "memory1")); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path3, "memory1")); assertThat(repositoryStore.getPaths()).containsOnly(path1, path2, path3); }
@Test public void getPathsResultsShouldNotBeDuplicatedWithTheSameProtocol() { repositoryStore.select(MEMORY1_REPO); repositoryStore.select(MEMORY1_REPO); assertThat(repositoryStore.getPaths()).containsExactly(PATH_REPO); }
@Test public void getPathsResultsShouldNotBeDuplicatedWithDifferentProtocols() { repositoryStore.select(MEMORY1_REPO); repositoryStore.select(MEMORY2_REPO); assertThat(repositoryStore.getPaths()).containsExactly(PATH_REPO); }
@Test public void selectShouldNotAddUrlWhenProtocolDoNotExist() { assertThatThrownBy(() -> repositoryStore.select(UNKNOWN_PROTOCOL_REPO)); assertThat(urlStore.listDistinct()).isEmpty(); }