use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class PopulatedLibraryScreenTest method setup.
@Before
public void setup() {
libraryServiceCaller = new CallerMock<>(libraryService);
libraryScreen = spy(new PopulatedLibraryScreen(view, libraryPlaces, libraryServiceCaller, projectController, projectContext, tileWidgets, addProjectButtonPresenter, projectCountUpdateEvent));
doReturn(true).when(projectController).canCreateProjects(any());
project1 = mockProject(PROJECT_1);
project2 = mockProject(PROJECT_2);
project3 = mockProject(PROJECT_3);
final List<WorkspaceProject> projects = new ArrayList<>();
projects.add(project1);
projects.add(project2);
projects.add(project3);
when(projectContext.getActiveOrganizationalUnit()).thenReturn(Optional.of(organizationalUnit));
when(projectContext.getActiveWorkspaceProject()).thenReturn(Optional.empty());
when(projectContext.getActiveModule()).thenReturn(Optional.empty());
when(projectContext.getActiveRepositoryRoot()).thenReturn(Optional.empty());
when(projectContext.getActivePackage()).thenReturn(Optional.empty());
final LibraryInfo libraryInfo = new LibraryInfo(projects);
doReturn(libraryInfo).when(libraryService).getLibraryInfo(organizationalUnit);
doReturn(mock(TileWidget.View.class)).when(tileWidget).getView();
when(tileWidgets.get()).thenAnswer((Answer<TileWidget<WorkspaceProject>>) invocationOnMock -> {
TileWidget tile = mock(TileWidget.class);
doReturn(mock(TileWidget.View.class)).when(tile).getView();
doAnswer((Answer<Void>) invocationOnMock1 -> {
when(tile.getContent()).thenReturn(invocationOnMock1.getArgument(0, WorkspaceProject.class));
return null;
}).when(tile).setContent(any());
return tile;
});
doReturn(mock(AddProjectButtonPresenter.View.class)).when(addProjectButtonPresenter).getView();
libraryScreen.setup();
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method setup.
@Before
public void setup() throws Exception {
when(spaceConfigStorageRegistry.get(Mockito.<String>any())).thenReturn(spaceConfigStorage);
when(spaceConfigStorageRegistry.getBatch(Mockito.<String>any())).thenReturn(new SpaceConfigStorageRegistryImpl.SpaceStorageBatchImpl(spaceConfigStorage));
when(spaceConfigStorageRegistry.exist(Mockito.<String>any())).thenReturn(true);
when(ou.getSpace()).thenReturn(space);
when(space.getName()).thenReturn("ou");
service = spy(new ExamplesServiceImpl(ioService, repositoryFactory, moduleService, ouService, projectService, metadataService, newProjectEvent, projectScreenService, validators, spaceConfigStorageRegistry, systemFS, pathUtil, repositoryService));
FileUtils.deleteDirectory(new File(".kie-wb-playground"));
when(this.validators.getValidators()).thenReturn(new ArrayList<>());
doAnswer(invocationOnMock -> {
String spaceName = (String) invocationOnMock.getArguments()[0];
String defaultGroupId = (String) invocationOnMock.getArguments()[1];
OrganizationalUnitImpl o = new OrganizationalUnitImpl(spaceName, defaultGroupId);
organizationalUnits.put(spaceName, o);
return o;
}).when(ouService).createOrganizationalUnit(Mockito.<String>any(), Mockito.<String>any());
doAnswer(invocationOnMock -> organizationalUnits.get(invocationOnMock.getArguments()[0])).when(ouService).getOrganizationalUnit(Mockito.<String>any());
when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {
{
add(new OrganizationalUnitImpl("ou1Name", "ou1GroupId"));
add(new OrganizationalUnitImpl("ou2Name", "ou2GroupId"));
}
});
when(moduleService.resolveModule(Mockito.<Path>any())).thenAnswer((Answer<KieModule>) invocationOnMock -> {
final Path path = (Path) invocationOnMock.getArguments()[0];
final KieModule module = new KieModule(path, path, path, path, path, path, mock(POM.class));
return module;
});
when(sessionInfo.getId()).thenReturn("sessionId");
when(sessionInfo.getIdentity()).thenReturn(user);
when(user.getIdentifier()).thenReturn("user");
doAnswer(invocationOnMock -> organizationalUnits.containsKey(invocationOnMock.getArguments()[0])).when(service).existSpace(any());
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class BranchManagementPresenterTest method setupWithUpdatableBranchesTest.
@Test
public void setupWithUpdatableBranchesTest() {
final Map<String, RolePermissions> permissionsByRole = new HashMap<>();
permissionsByRole.put("CONTRIBUTOR", new RolePermissions("CONTRIBUTOR", true, false, true, true));
doReturn(new BranchPermissions("myBranch", permissionsByRole)).when(libraryService).loadBranchPermissions("mySpace", "myProject", "myBranch");
doReturn(promises.resolve(Arrays.asList(new Branch("main", mock(Path.class)), new Branch("myBranch", mock(Path.class))))).when(projectController).getUpdatableBranches(any());
presenter.setup(mock(ProjectScreenModel.class)).then(v -> {
assertEquals("myBranch", presenter.selectedBranch);
verify(view).init(presenter);
verify(view, never()).showEmptyState();
verify(view).setupBranchSelect(any(), any(), any());
verify(libraryService).loadBranchPermissions("mySpace", "myProject", "myBranch");
return promises.resolve();
}).catch_(error -> {
fail();
return promises.resolve();
});
}
use of org.mockito.Mock in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SearchResultServletTest method setUpQueryBuilder.
/**
* Sets up a mock query builder.
* If there are any results then `this.spyResolver` will be set to a non-null value.
*
* Note: any query executed on the query builder configured by calling this method will simply list all of the
* child pages of the search path. No actual search, or other predicates on the query will be honoured. Therefore,
* the results from the query builder cannot be trusted for testing purposes beyond testing the search root and
* the handling / transformation of results.
*/
public void setUpQueryBuilder() {
doAnswer(invocationOnQueryBuilder -> {
PredicateGroup predicateGroup = invocationOnQueryBuilder.getArgument(0);
Query query = Mockito.mock(Query.class);
doAnswer(invocationOnQuery -> {
SearchResult result = Mockito.mock(SearchResult.class);
doAnswer(invocationOnResult -> {
String searchPath = predicateGroup.getByName(PathPredicateEvaluator.PATH).get(PathPredicateEvaluator.PATH);
Iterator<Resource> res = Objects.requireNonNull(this.context.resourceResolver().getResource(searchPath)).listChildren();
List<Resource> resources = StreamSupport.stream(Spliterators.spliteratorUnknownSize(res, Spliterator.ORDERED), false).filter(r -> r.isResourceType("cq:Page")).collect(Collectors.toList());
if (resources.size() > 0) {
this.spyResolver = Mockito.spy(this.context.resourceResolver());
doNothing().when(spyResolver).close();
Resource spyResource = Mockito.spy(resources.get(0));
doAnswer(invocationOnMock3 -> spyResolver).when(spyResource).getResourceResolver();
resources.set(0, spyResource);
}
return resources.iterator();
}).when(result).getResources();
return result;
}).when(query).getResult();
return query;
}).when(mockQueryBuilder).createQuery(any(), any());
}
use of org.mockito.Mock in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method customizerShouldBeAppliedAtTheEnd.
@Test
void customizerShouldBeAppliedAtTheEnd() {
ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
this.builder.interceptors(this.interceptor).messageConverters(this.messageConverter).rootUri("http://localhost:8080").errorHandler(errorHandler).basicAuthentication("spring", "boot").requestFactory(() -> requestFactory).customizers((restTemplate) -> {
assertThat(restTemplate.getInterceptors()).hasSize(1);
assertThat(restTemplate.getMessageConverters()).contains(this.messageConverter);
assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(RootUriTemplateHandler.class);
assertThat(restTemplate.getErrorHandler()).isEqualTo(errorHandler);
ClientHttpRequestFactory actualRequestFactory = restTemplate.getRequestFactory();
assertThat(actualRequestFactory).isInstanceOf(InterceptingClientHttpRequestFactory.class);
ClientHttpRequestInitializer initializer = restTemplate.getClientHttpRequestInitializers().get(0);
assertThat(initializer).isInstanceOf(RestTemplateBuilderClientHttpRequestInitializer.class);
}).build();
}
Aggregations