NamedParamRepositoryFactory { public NamedParamRepository create(RepositoryName repositoryName, ParamRepository repository) { return new NamedParamRepository(repositoryName, repository); } NamedParamRepositoryFactory(); NamedParamRepository create(RepositoryName repositoryName, ParamRepository repository); NamedParamRepository create(String repositoryName, ParamRepository repository); NamedParamRepository create(ParamRepository repository);  }
@Test public void shouldReturnNamedParamRepositoryProducedFromRepositoryNameAndRepository() { ParamRepository repository = mock(ParamRepository.class); NamedParamRepositoryFactory factory = new NamedParamRepositoryFactory(); NamedParamRepository namedRepository = factory.create(RepositoryName.from("test"), repository); assertThat(namedRepository).containsRepository(repository).hasName("test"); }
@Test public void shouldReturnNamedParamRepositoryProducedFromStringAsNameAndRepository() { ParamRepository repository = mock(ParamRepository.class); NamedParamRepositoryFactory factory = new NamedParamRepositoryFactory(); NamedParamRepository namedRepository = factory.create("test", repository); assertThat(namedRepository).containsRepository(repository).hasName("test"); }
@Test public void shouldAutoGenerateRepositoryNameFromClassSimpleNameWhenNoneSpecified() { ParamRepository repository = mock(ParamRepository.class); String repositoryClassName = repository.getClass().getSimpleName(); NamedParamRepositoryFactory factory = new NamedParamRepositoryFactory(); NamedParamRepository namedRepository = factory.create(repository); assertThat(namedRepository).hasName(repositoryClassName); }
@Test public void shouldAddOccurrenceNumberToAutoGeneratedNameWhenMultipleRepositoriesWithSameClassProvided() { ParamRepository repository = mock(ParamRepository.class); String repositoryClassName = repository.getClass().getSimpleName(); NamedParamRepositoryFactory factory = new NamedParamRepositoryFactory(); factory.create(repository); NamedParamRepository namedRepository1 = factory.create(repository); NamedParamRepository namedRepository2 = factory.create(repository); assertThat(namedRepository1).hasName(repositoryClassName + "1"); assertThat(namedRepository2).hasName(repositoryClassName + "2"); }