use of org.mockito.Mock in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class InstantAppButtonsPreferenceControllerTest method clickInstallButton_shouldOpenAppStore.
@Test
public void clickInstallButton_shouldOpenAppStore() {
final ResolveInfo resolveInfo = mock(ResolveInfo.class);
final ActivityInfo activityInfo = mock(ActivityInfo.class);
resolveInfo.activityInfo = activityInfo;
activityInfo.packageName = TEST_INSTALLER_PACKAGE_NAME;
activityInfo.name = TEST_INSTALLER_ACTIVITY_NAME;
when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo);
mController.displayPreference(mScreen);
final ComponentName componentName = new ComponentName(TEST_INSTALLER_PACKAGE_NAME, TEST_INSTALLER_ACTIVITY_NAME);
mInstallButton.callOnClick();
verify(mFragment).startActivity(argThat(intent -> intent != null && intent.getAction().equals(Intent.ACTION_SHOW_APP_INFO) && intent.getComponent().equals(componentName)));
}
use of org.mockito.Mock in project graylog2-server by Graylog2.
the class ElasticsearchBackendErrorHandlingTest method setUp.
@Before
public void setUp() throws Exception {
final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
this.backend = new ElasticsearchBackend(ImmutableMap.of("dummy", () -> mock(DummyHandler.class)), jestClient, indexLookup, new QueryStringDecorators(Collections.emptySet()), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
when(indexLookup.indexNamesForStreamsInTimeRange(any(), any())).thenReturn(Collections.emptySet());
final SearchType searchType1 = mock(SearchType.class);
when(searchType1.id()).thenReturn("deadbeef");
when(searchType1.type()).thenReturn("dummy");
final SearchType searchType2 = mock(SearchType.class);
when(searchType2.id()).thenReturn("cafeaffe");
when(searchType2.type()).thenReturn("dummy");
final Set<SearchType> searchTypes = ImmutableSet.of(searchType1, searchType2);
this.query = Query.builder().id("query1").timerange(RelativeRange.create(300)).query(ElasticsearchQueryString.of("*")).searchTypes(searchTypes).build();
final Search search = Search.builder().id("search1").queries(ImmutableSet.of(query)).build();
this.searchJob = new SearchJob("job1", search, "admin");
this.queryContext = new ESGeneratedQueryContext(this.backend, new SearchSourceBuilder(), searchJob, query, mock(FieldTypesLookup.class));
searchTypes.forEach(queryContext::searchSourceBuilder);
when(jestClient.execute(any())).thenReturn(result);
}
use of org.mockito.Mock in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method ignoreInvisibleOwners.
@DisplayName("The validation should ignore invisble owners")
@Test
void ignoreInvisibleOwners() {
final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of());
final Set<GRN> allGrantees = dbGrantService.getAll().stream().map(GrantDTO::grantee).collect(Collectors.toSet());
lenient().when(granteeService.getAvailableGrantees(any())).thenReturn(allGrantees.stream().filter(g -> g.toString().equals("grn::::user:invisible")).map(g -> Grantee.createUser(g, g.entity())).collect(Collectors.toSet()));
final User user = createMockUser("hans");
final Subject subject = mock(Subject.class);
final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
assertThat(validationResult.failed()).isFalse();
});
}
use of org.mockito.Mock in project graylog2-server by Graylog2.
the class QualifyingViewsServiceTest method returnViewWhenBothSearchesWithAndWithoutParametersIsPresent.
@Test
public void returnViewWhenBothSearchesWithAndWithoutParametersIsPresent() {
final ViewDTO view1 = mock(ViewDTO.class);
final ViewDTO view2 = mock(ViewDTO.class);
final String viewId = "viewWithParameter";
final Search search1 = mock(Search.class);
final Search search2 = mock(Search.class);
final String search1Id = "streamWithParameter";
when(view1.id()).thenReturn(viewId);
when(view1.type()).thenReturn(ViewDTO.Type.SEARCH);
when(view1.searchId()).thenReturn(search1Id);
when(view1.title()).thenReturn("My View");
when(view1.summary()).thenReturn("My Summary");
when(view1.description()).thenReturn("My Description");
when(view2.type()).thenReturn(ViewDTO.Type.SEARCH);
when(search1.id()).thenReturn(search1Id);
when(search1.parameters()).thenReturn(ImmutableSet.of(ValueParameter.any("foobar")));
when(search2.parameters()).thenReturn(ImmutableSet.of());
when(viewService.streamAll()).then(invocation -> Stream.of(view1, view2));
when(searchDbService.findByIds(any())).thenReturn(ImmutableList.of(search1, search2));
final Collection<ViewParameterSummaryDTO> result = this.qualifyingViewsService.forValue();
assertThat(result).hasSize(1).allMatch(summary -> summary.id().equals(viewId)).allMatch(summary -> summary.title().equals("My View")).allMatch(summary -> summary.summary().equals("My Summary")).allMatch(summary -> summary.description().equals("My Description"));
}
use of org.mockito.Mock in project graylog2-server by Graylog2.
the class QualifyingViewsServiceTest method returnViewWhenSearchWithParametersIsPresent.
@Test
public void returnViewWhenSearchWithParametersIsPresent() {
final ViewDTO view1 = mock(ViewDTO.class);
final String viewId = "viewWithParameter";
final Search search = mock(Search.class);
final String searchId = "streamWithParameter";
when(view1.id()).thenReturn(viewId);
when(view1.type()).thenReturn(ViewDTO.Type.SEARCH);
when(view1.searchId()).thenReturn(searchId);
when(view1.title()).thenReturn("My View");
when(view1.summary()).thenReturn("My Summary");
when(view1.description()).thenReturn("My Description");
when(search.id()).thenReturn(searchId);
when(search.parameters()).thenReturn(ImmutableSet.of(ValueParameter.any("foobar")));
when(viewService.streamAll()).then(invocation -> Stream.of(view1));
when(searchDbService.findByIds(any())).thenReturn(ImmutableList.of(search));
final Collection<ViewParameterSummaryDTO> result = this.qualifyingViewsService.forValue();
assertThat(result).hasSize(1).allMatch(summary -> summary.id().equals(viewId)).allMatch(summary -> summary.title().equals("My View")).allMatch(summary -> summary.summary().equals("My Summary")).allMatch(summary -> summary.description().equals("My Description"));
}
Aggregations