### Question:
ArchetypeServiceImpl implements ArchetypeService { public void onNewOrganizationalUnitEvent(final @Observes NewOrganizationalUnitEvent newOrganizationalUnitEvent) { final OrganizationalUnit newOU = newOrganizationalUnitEvent.getOrganizationalUnit(); if (isArchetypesOUAvailable() && !newOU.getName().equals(ArchetypeConfigStorageImpl.ARCHETYPES_SPACE_NAME)) { archetypePreferencesManager.initializeCustomPreference(newOU.getIdentifier()); } } 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 public void newOrgUnitEventWhenArchetypesOrgUnitNotAvailableTest() { doReturn(Collections.emptyList()).when(ouService).getAllOrganizationalUnits(eq(false), any()); service.onNewOrganizationalUnitEvent(mock(NewOrganizationalUnitEvent.class)); verify(archetypePreferencesManager, never()).initializeCustomPreference(anyString()); }
@Test public void newOrgUnitEventWhenIsArchetypesOrgUnitTest() { doReturn(Collections.nCopies(10, mock(OrganizationalUnit.class))) .when(ouService).getAllOrganizationalUnits(eq(false), any()); final NewOrganizationalUnitEvent event = mock(NewOrganizationalUnitEvent.class); final OrganizationalUnit orgUnit = mock(OrganizationalUnit.class); doReturn(ArchetypeConfigStorageImpl.ARCHETYPES_SPACE_NAME).when(orgUnit).getName(); doReturn(orgUnit).when(event).getOrganizationalUnit(); service.onNewOrganizationalUnitEvent(event); verify(archetypePreferencesManager, never()).initializeCustomPreference(anyString()); }
@Test public void newOrgUnitEventWhenShouldInitializePreferencesTest() { doReturn(Collections.nCopies(10, mock(OrganizationalUnit.class))) .when(ouService).getAllOrganizationalUnits(eq(false), any()); final NewOrganizationalUnitEvent event = mock(NewOrganizationalUnitEvent.class); final OrganizationalUnit orgUnit = mock(OrganizationalUnit.class); doReturn("new-org-unit").when(orgUnit).getName(); doReturn(orgUnit).when(event).getOrganizationalUnit(); service.onNewOrganizationalUnitEvent(event); verify(archetypePreferencesManager).initializeCustomPreference(anyString()); }