### Question:
ArchetypeServiceImpl implements ArchetypeService { @Override public Repository getTemplateRepository(final String alias) { checkNotEmpty(ALIAS_PARAM, alias); final Repository repository = resolveRepository(alias); if (repository != null) { checkTemplateShouldBeValid(alias); return repository; } throw new IllegalStateException(String.format("Repository %s cannot be resolved.", alias)); } ArchetypeServiceImpl(); @Inject  ArchetypeServiceImpl(final @Named("ioStrategy") IOService ioService,
                                final RepositoryService repositoryService,
                                final OrganizationalUnitService ouService,
                                final Event<ArchetypeListUpdatedEvent> archetypeListUpdatedEvent,
                                final ArchetypeConfigStorage archetypeConfigStorage,
                                final PathUtil pathUtil,
                                final ArchetypePreferencesManager archetypePreferencesManager,
                                final KieModuleService moduleService,
                                final POMService pomService); void onNewOrganizationalUnitEvent(final @Observes NewOrganizationalUnitEvent newOrganizationalUnitEvent); @Override void add(final GAV archetypeGav); @Override void add(final GAV archetypeGav,
                    final GAV templateGav); @Override PaginatedArchetypeList list(final Integer page,
                                       final Integer pageSize,
                                       final String filter); @Override PaginatedArchetypeList list(final Integer page,
                                       final Integer pageSize,
                                       final String filter,
                                       final ArchetypeStatus status); @Override void delete(final String alias); @Override void validateAll(); @Override void validate(final String alias); @Override Repository getTemplateRepository(final String alias); @Override Optional<Repository> getBaseKieTemplateRepository(); @Override Optional<Archetype> getBaseKieArchetype();  }### Answer:
@Test(expected = IllegalArgumentException.class) public void getTemplateRepositoryWhenInvalidAliasTest() { service.getTemplateRepository(null); }
@Test(expected = IllegalStateException.class) public void getTemplateRepositoryWhenInvalidStatusTest() { mockArchetypesOrgUnit(); final Archetype archetype = mock(Archetype.class); doReturn(ArchetypeStatus.INVALID).when(archetype).getStatus(); doReturn(archetype).when(archetypeConfigStorage).loadArchetype(anyString()); service.getTemplateRepository(COMMON_ARCHETYPE_ALIAS); }
@Test(expected = IllegalStateException.class) public void getTemplateRepositoryWhenOrgUnitIsNotAvailableTest() { mockArchetypesOrgUnitNotAvailable(); service.getTemplateRepository(COMMON_ARCHETYPE_ALIAS); }
@Test(expected = IllegalStateException.class) public void getTemplateRepositoryWhenRepositoryIsNotAvailableTest() { mockArchetypesOrgUnit(); doReturn(null).when(repositoryService).getRepositoryFromSpace(any(Space.class), anyString()); service.getTemplateRepository(COMMON_ARCHETYPE_ALIAS); }
@Test(expected = IllegalStateException.class) public void getTemplateRepositoryWhenArchetypeIsInvalidTest() { mockArchetypesOrgUnit(); final Archetype archetype = mock(Archetype.class); doReturn(ArchetypeStatus.INVALID).when(archetype).getStatus(); doReturn(archetype).when(archetypeConfigStorage).loadArchetype(anyString()); doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(any(Space.class), anyString()); service.getTemplateRepository(COMMON_ARCHETYPE_ALIAS); }
@Test public void getTemplateRepositorySuccessTest() { mockArchetypesOrgUnit(); final Archetype archetype = mock(Archetype.class); doReturn(ArchetypeStatus.VALID).when(archetype).getStatus(); doReturn(archetype).when(archetypeConfigStorage).loadArchetype(anyString()); final Repository expectedRepository = mock(Repository.class); doReturn(expectedRepository).when(repositoryService).getRepositoryFromSpace(any(Space.class), eq(COMMON_ARCHETYPE_ALIAS)); final Repository repository = service.getTemplateRepository(COMMON_ARCHETYPE_ALIAS); assertSame(expectedRepository, repository); }