org.mockito.hamcrest.MockitoHamcrest Java Examples
The following examples show how to use
org.mockito.hamcrest.MockitoHamcrest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TLSConfigurerTest.java From spring-boot-security-saml with MIT License | 6 votes |
@Test public void configure_custom() throws Exception { TLSConfigurer configurer = spy(new TLSConfigurer()); TLSProtocolConfigurer tlsProtocolConfigurer = mock(TLSProtocolConfigurer.class); when(configurer.createDefaultTlsProtocolConfigurer()).thenReturn(tlsProtocolConfigurer); configurer .protocolName("protocol") .protocolPort(9999) .sslHostnameVerification("strict") .trustedKeys("one", "two"); configurer.init(builder); configurer.configure(builder); verify(tlsConfig, never()).getProtocolName(); verify(tlsConfig, never()).getProtocolPort(); verify(tlsConfig, never()).getSslHostnameVerification(); verify(tlsConfig, never()).getTrustedKeys(); verify(builder).setSharedObject(eq(TLSProtocolConfigurer.class), eq(tlsProtocolConfigurer)); verify(tlsProtocolConfigurer).setProtocolName(eq("protocol")); verify(tlsProtocolConfigurer).setProtocolPort(eq(9999)); verify(tlsProtocolConfigurer).setSslHostnameVerification(eq("strict")); verify(tlsProtocolConfigurer).setTrustedKeys((Set<String>) MockitoHamcrest.argThat(contains("one", "two"))); }
Example #2
Source File: ViewInteractionTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void verifyFailingCheckWithSuccessfulRemoteInteraction() { initWithRunCheckWithSuccessfulRemoteInteraction(); initWithViewInteraction(); testInteraction.check(mockAssertion); verify(mockRemoteInteraction).isRemoteProcess(); // noinspection unchecked verify(mockRemoteInteraction) .createRemoteCheckCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)))), any(ViewAssertion.class)); }
Example #3
Source File: WorkspaceASTFunctionTest.java From bazel with Apache License 2.0 | 6 votes |
private SkyFunction.Environment getEnv() throws InterruptedException { SkyFunction.Environment env = Mockito.mock(SkyFunction.Environment.class); Mockito.when(env.getValue(MockitoHamcrest.argThat(new SkyKeyMatchers(FileValue.FILE)))) .thenReturn(fakeWorkspaceFileValue); Mockito.when( env.getValue(MockitoHamcrest.argThat(new SkyKeyMatchers(SkyFunctions.PRECOMPUTED)))) .thenReturn(new PrecomputedValue(Optional.<RootedPath>absent())); Mockito.when( env.getValue( MockitoHamcrest.argThat( new SkyKeyMatchers(SkyFunctions.PRECOMPUTED) { @Override public boolean matches(Object item) { return super.matches(item) && item.toString().equals("PRECOMPUTED:starlark_semantics"); } }))) .thenReturn(null); return env; }
Example #4
Source File: ViewInteractionTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void verifySuccessfulCheckWithFailingRemoteInteraction() { Callable<Void> failingRemoteInteraction = new Callable<Void>() { @Override public Void call() throws Exception { throw new NoRemoteEspressoInstanceException("No remote instances available"); } }; when(mockViewFinder.getView()).thenReturn(targetView); // enable remote interaction when(mockRemoteInteraction.isRemoteProcess()).thenReturn(false); // noinspection unchecked when(mockRemoteInteraction.createRemoteCheckCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)))), any(ViewAssertion.class))) .thenReturn(failingRemoteInteraction); initWithViewInteraction(); testInteraction.check(mockAssertion); verify(mockAssertion).check(targetView, null); }
Example #5
Source File: ViewInteractionTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void verifyPerformWithMultipleIBinders() { initWithRunPerformWithSuccessfulRemoteInteraction(); initWithViewInteraction(); String bindableViewActionId = BindableViewAction.class.getSimpleName(); when(bindableMock.getId()).thenReturn(bindableViewActionId); when(bindableMock.getIBinder()).thenReturn(iBinderMock); ViewAction bindableViewAction = new BindableViewAction(mockAction, bindableMock); testInteraction.perform(bindableViewAction); // noinspection unchecked verify(mockRemoteInteraction) .createRemotePerformCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)), hasEntry(equalTo(bindableViewActionId), instanceOf(IBinder.class)))), any(ViewAction.class)); verify(bindableMock).getId(); verify(bindableMock).getIBinder(); }
Example #6
Source File: ViewInteractionTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void verifyCheckWithMultipleIBinders() { initWithRunCheckWithSuccessfulRemoteInteraction(); initWithViewInteraction(); String bindableViewAssertionId = "test"; when(bindableMock.getId()).thenReturn(bindableViewAssertionId); when(bindableMock.getIBinder()).thenReturn(iBinderMock); BindableViewAssertion bindableViewAssertion = new BindableViewAssertion(mockAssertion, bindableMock); testInteraction.check(bindableViewAssertion); // noinspection unchecked verify(mockRemoteInteraction) .createRemoteCheckCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)), hasEntry(equalTo(bindableViewAssertionId), instanceOf(IBinder.class)))), any(ViewAssertion.class)); verify(bindableMock).getId(); verify(bindableMock).getIBinder(); }
Example #7
Source File: ChallengeFormatTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private static void setupChallengeMock(PlayerInfo playerInfo, String challengeName, String displayName) { ChallengeCompletion challengeCompletion = Mockito.mock(ChallengeCompletion.class); when(challengeCompletion.getTimesCompleted()).thenReturn(0); when(challengeCompletion.getName()).thenReturn(challengeName); when(playerInfo.getChallenge(MockitoHamcrest.argThat(is(challengeName)))).thenReturn(challengeCompletion); Challenge challenge = Mockito.mock(Challenge.class); when(challenge.getDisplayName()).thenReturn(displayName); when(challengeLogic.getChallenge(MockitoHamcrest.argThat(is(challengeName)))).thenReturn(challenge); }
Example #8
Source File: HealthCheckingLoadBalancerFactoryTest.java From grpc-java with Apache License 2.0 | 5 votes |
private ConnectivityStateInfo unavailableStateWithMsg(final String expectedMsg) { return MockitoHamcrest.argThat( new org.hamcrest.BaseMatcher<ConnectivityStateInfo>() { @Override public boolean matches(Object item) { if (!(item instanceof ConnectivityStateInfo)) { return false; } ConnectivityStateInfo info = (ConnectivityStateInfo) item; if (!info.getState().equals(TRANSIENT_FAILURE)) { return false; } Status error = info.getStatus(); if (!error.getCode().equals(Code.UNAVAILABLE)) { return false; } if (!error.getDescription().equals(expectedMsg)) { return false; } return true; } @Override public void describeTo(org.hamcrest.Description desc) { desc.appendText("Matches unavailable state with msg='" + expectedMsg + "'"); } }); }
Example #9
Source File: MetadataManagerConfigurerTest.java From spring-boot-security-saml with MIT License | 4 votes |
@Test public void configure_arguments() throws Exception { MetadataManagerConfigurer configurer = spy(new MetadataManagerConfigurer()); CachingMetadataManager metadataManager = mock(CachingMetadataManager.class); when(configurer.createDefaultMetadataManager()).thenReturn(metadataManager); ResourceBackedMetadataProvider provider = mock(ResourceBackedMetadataProvider.class); doReturn(provider).when(configurer).createDefaultMetadataProvider("classpath:idp-provided.xml"); ExtendedMetadataDelegate delegate = mock(ExtendedMetadataDelegate.class); doReturn(delegate).when(configurer).createDefaultExtendedMetadataDelegate(eq(provider), any(ExtendedMetadata.class)); MetadataFilter metadataFilter = mock(MetadataFilter.class); configurer.setBuilder(builder); configurer .metadataLocations("classpath:idp-provided.xml") .defaultIDP("default") .hostedSPName("spname") .refreshCheckInterval(999L) .forceMetadataRevocationCheck(true) .metadataRequireSignature(true) .metadataTrustCheck(true) .requireValidMetadata(true) .metadataTrustedKeys("one", "two") .metadataFilter(metadataFilter); configurer.init(builder); configurer.configure(builder); verify(builder).setSharedObject(eq(MetadataManager.class), eq(metadataManager)); ArgumentCaptor<List> providersCaptor = ArgumentCaptor.forClass(List.class); verify(metadataManager).setProviders((List<MetadataProvider>) providersCaptor.capture()); verify(configurer).createDefaultMetadataProvider(eq("classpath:idp-provided.xml")); verify(configurer).createDefaultExtendedMetadataDelegate(eq(provider), any()); verify(metadataManagerProperties, never()).getDefaultIdp(); verify(metadataManagerProperties, never()).getHostedSpName(); verify(metadataManagerProperties, never()).getRefreshCheckInterval(); verify(extendedMetadataDelegateProperties, never()).isForceMetadataRevocationCheck(); verify(extendedMetadataDelegateProperties, never()).isMetadataRequireSignature(); verify(extendedMetadataDelegateProperties, never()).isMetadataTrustCheck(); verify(extendedMetadataDelegateProperties, never()).isRequireValidMetadata(); verify(extendedMetadataDelegateProperties, never()).getMetadataTrustedKeys(); List<MetadataProvider> providers = providersCaptor.getValue(); assertThat(providers).hasSize(1); assertThat(providers.get(0)).isEqualTo(delegate); verify(metadataManager).setDefaultIDP(eq("default")); verify(metadataManager).setHostedSPName(eq("spname")); verify(metadataManager).setRefreshCheckInterval(eq(999L)); verify(delegate).setForceMetadataRevocationCheck(eq(true)); verify(delegate).setMetadataRequireSignature(eq(true)); verify(delegate).setMetadataTrustCheck(eq(true)); verify(delegate).setMetadataTrustedKeys((Set<String>) MockitoHamcrest.argThat(contains("one", "two"))); verify(delegate).setRequireValidMetadata(eq(true)); verify(delegate).setMetadataFilter(eq(metadataFilter)); }
Example #10
Source File: BatchDataflowWorkerTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void testWhenNoWorkIsReturnedThatWeImmediatelyRetry() throws Exception { final String workItemId = "14"; BatchDataflowWorker worker = new BatchDataflowWorker( null /* pipeline */, SdkHarnessRegistries.emptySdkHarnessRegistry(), mockWorkUnitClient, IntrinsicMapTaskExecutorFactory.defaultFactory(), options); WorkItem workItem = new WorkItem(); workItem.setId(Long.parseLong(workItemId)); workItem.setJobId("SuccessfulEmptyMapTask"); workItem.setInitialReportIndex(12L); workItem.setMapTask( new MapTask() .setInstructions(new ArrayList<ParallelInstruction>()) .setStageName("testStage")); workItem.setLeaseExpireTime(TimeUtil.toCloudTime(Instant.now())); workItem.setReportStatusInterval(TimeUtil.toCloudDuration(Duration.standardMinutes(1))); when(mockWorkUnitClient.getWorkItem()) .thenReturn(Optional.<WorkItem>absent()) .thenReturn(Optional.of(workItem)); assertTrue(worker.getAndPerformWork()); verify(mockWorkUnitClient) .reportWorkItemStatus( MockitoHamcrest.argThat( new TypeSafeMatcher<WorkItemStatus>() { @Override public void describeTo(Description description) {} @Override protected boolean matchesSafely(WorkItemStatus item) { assertTrue(item.getCompleted()); assertEquals(workItemId, item.getWorkItemId()); return true; } })); }
Example #11
Source File: ViewInteractionTest.java From android-test with Apache License 2.0 | 4 votes |
@Test public void verifyFailingCheckWithFailingRemoteInteractionPropagatesError() { NoActivityResumedException noActivityResumed = new NoActivityResumedException( "No activities in stage RESUMED. Did you forget to launch the activity. " + "(test.getActivity() or similar)?"); Callable<Void> failingRemoteInteraction = new Callable<Void>() { @Override public Void call() throws Exception { throw new NoRemoteEspressoInstanceException("No remote instances available"); } }; // fail local interaction in order to force wait for the remote interaction to finish when(mockViewFinder.getView()).thenThrow(noActivityResumed); // enable remote interaction when(mockRemoteInteraction.isRemoteProcess()).thenReturn(false); // noinspection unchecked when(mockRemoteInteraction.createRemoteCheckCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)))), any(ViewAssertion.class))) .thenReturn(failingRemoteInteraction); initWithViewInteraction(); try { testInteraction.check(mockAssertion); fail("expected NoRemoteEspressoInstanceException"); } catch (NoActivityResumedException e) { // ensure local NoActivityResumedException takes precedence over // remote NoRemoteEspressoInstanceException assertThat(e, is(noActivityResumed)); verify(mockRemoteInteraction).isRemoteProcess(); // noinspection unchecked verify(mockRemoteInteraction) .createRemoteCheckCallable( any(Matcher.class), any(Matcher.class), MockitoHamcrest.argThat( allOf( hasEntry( equalTo(RemoteInteraction.BUNDLE_EXECUTION_STATUS), instanceOf(IBinder.class)))), any(ViewAssertion.class)); } }