本文整理汇总了Java中org.mockito.internal.verification.VerificationModeFactory类的典型用法代码示例。如果您正苦于以下问题:Java VerificationModeFactory类的具体用法?Java VerificationModeFactory怎么用?Java VerificationModeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VerificationModeFactory类属于org.mockito.internal.verification包,在下文中一共展示了VerificationModeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUser
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void addUser() {
final Set<String> users = new HashSet<>();
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
return new GroupOrg("dc=" + name, name, users);
}
};
final LdapCacheRepository cacheRepository = Mockito.mock(LdapCacheRepository.class);
groupRepository.setLdapCacheRepository(cacheRepository);
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
addUser(groupRepository);
Mockito.verify(cacheRepository, VerificationModeFactory.times(1)).addUserToGroup(ArgumentMatchers.any(UserOrg.class),
ArgumentMatchers.any(GroupOrg.class));
}
示例2: authenticateSecondaryAccept
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void authenticateSecondaryAccept() throws Exception {
final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
final IdentityServicePlugin servicePlugin = Mockito.mock(IdentityServicePlugin.class);
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
.thenReturn(servicePlugin);
Mockito.when(servicePlugin.accept(authentication, "service:id:ldap:adu")).thenReturn(true);
Mockito.when(servicePlugin.authenticate(authentication, "service:id:ldap:adu", false))
.thenReturn(authentication2);
Assert.assertSame(authentication2, provider.authenticate(authentication));
Mockito.verify(provider.servicePluginLocator, VerificationModeFactory.times(0))
.getResource("service:id:ldap:dig", IdentityServicePlugin.class);
}
示例3: authenticateSecondaryDontAccept
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void authenticateSecondaryDontAccept() throws Exception {
final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
final IdentityServicePlugin servicePluginSecondary = Mockito.mock(IdentityServicePlugin.class);
final IdentityServicePlugin servicePluginPrimary = Mockito.mock(IdentityServicePlugin.class);
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
.thenReturn(servicePluginSecondary);
Mockito.when(servicePluginPrimary.authenticate(authentication, "service:id:ldap:dig", true))
.thenReturn(authentication2);
Mockito.when(
provider.servicePluginLocator.getResourceExpected("service:id:ldap:dig", IdentityServicePlugin.class))
.thenReturn(servicePluginPrimary);
Assert.assertSame(authentication2, provider.authenticate(authentication));
Mockito.verify(servicePluginSecondary, VerificationModeFactory.times(0)).authenticate(authentication,
"service:id:ldap:adu", false);
}
示例4: filter404SingleParameter
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void filter404SingleParameter() {
final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
Mockito.when(responseContext.getStatus()).thenReturn(204);
final Annotation anno1 = Mockito.mock(Annotation.class);
final Annotation anno2 = Mockito.mock(Annotation.class);
final Annotation[] annotations = new Annotation[] { anno1, anno2 };
Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);
final UriInfo uriInfo = Mockito.mock(UriInfo.class);
final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();
parameters.putSingle("id", "2000");
Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
filter.filter(requestContext, responseContext);
Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setEntity(
"{\"code\":\"entity\",\"message\":\"2000\",\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
示例5: filter404NoParameter
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void filter404NoParameter() {
final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
Mockito.when(responseContext.getStatus()).thenReturn(204);
final Annotation anno1 = Mockito.mock(Annotation.class);
final Annotation anno2 = Mockito.mock(Annotation.class);
final Annotation[] annotations = new Annotation[] { anno1, anno2 };
Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);
final UriInfo uriInfo = Mockito.mock(UriInfo.class);
final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();
Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
filter.filter(requestContext, responseContext);
Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce())
.setEntity("{\"code\":\"data\",\"message\":null,\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
示例6: testPutSecretNewVersion
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testPutSecretNewVersion() {
String version = "foover";
final PutItemRequest[] putItemRequest = new PutItemRequest[1];
Mockito.when(dynamoDBClient.putItem(Mockito.any(PutItemRequest.class))).thenAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
putItemRequest[0] = (PutItemRequest) args[0];
return new PutItemResult();
});
JCredStash credStash = new JCredStash(dynamoDBClient, awskmsClient);
credStash.putSecret("table", "mysecret", "foo", "alias/foo", new HashMap<>(), version);
Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).putItem(Mockito.any(PutItemRequest.class));
Assert.assertEquals(putItemRequest[0].getItem().get("version").getS(), version);
}
示例7: testPutSecretAutoIncrementVersion
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testPutSecretAutoIncrementVersion() {
final PutItemRequest[] putItemRequest = new PutItemRequest[1];
Mockito.when(dynamoDBClient.putItem(Mockito.any(PutItemRequest.class))).thenAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
putItemRequest[0] = (PutItemRequest) args[0];
return new PutItemResult();
});
JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
Mockito.doReturn(padVersion(1)).when(credStash).getHighestVersion("table", "mysecret");
credStash.putSecret("table", "mysecret", "foo", "alias/foo", new HashMap<>());
Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).putItem(Mockito.any(PutItemRequest.class));
Assert.assertEquals(putItemRequest[0].getItem().get("version").getS(), padVersion(2));
}
示例8: testGetSecret
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testGetSecret() {
final QueryRequest[] queryRequest = new QueryRequest[1];
Mockito.when(dynamoDBClient.query(Mockito.any(QueryRequest.class))).thenAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
queryRequest[0] = (QueryRequest) args[0];
return new QueryResult().withCount(1).withItems(Arrays.asList(
mockItem("mysecret", padVersion(1), new byte[]{}, new byte[]{}, new byte[]{})
));
});
JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
Mockito.doReturn("foo").when(credStash).getSecret(Mockito.any(JCredStash.StoredSecret.class), Mockito.any(Map.class));
String secret = credStash.getSecret("table", "mysecret", new HashMap<>());
Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).query(Mockito.any(QueryRequest.class));
Assert.assertEquals("foo", secret);
}
示例9: testGetSecretWithVersion
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testGetSecretWithVersion() {
final GetItemRequest[] getItemRequest = new GetItemRequest[1];
Mockito.when(dynamoDBClient.getItem(Mockito.any(GetItemRequest.class))).thenAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
getItemRequest[0] = (GetItemRequest) args[0];
return new GetItemResult();
});
JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
Mockito.doReturn("foo").when(credStash).getSecret(Mockito.any(JCredStash.StoredSecret.class), Mockito.any(Map.class));
credStash.getSecret("table", "mysecret", new HashMap<>(), padVersion(1));
Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).getItem(Mockito.any(GetItemRequest.class));
Assert.assertEquals(getItemRequest[0].getKey().get("version").getS(), padVersion(1));
}
示例10: shouldLaunchUriWithFallbackIfCustomTabIntentFails
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void shouldLaunchUriWithFallbackIfCustomTabIntentFails() throws Exception {
doThrow(ActivityNotFoundException.class)
.doNothing()
.when(context).startActivity(any(Intent.class));
controller.launchUri(uri);
verify(context, new Timeout(MAX_TEST_WAIT_TIME_MS, VerificationModeFactory.times(2))).startActivity(launchIntentCaptor.capture());
List<Intent> intents = launchIntentCaptor.getAllValues();
Intent customTabIntent = intents.get(0);
assertThat(customTabIntent.getAction(), is(Intent.ACTION_VIEW));
assertThat(customTabIntent.getData(), is(uri));
assertThat(customTabIntent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(true));
assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
assertThat(customTabIntent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.NO_TITLE));
Intent fallbackIntent = intents.get(1);
assertThat(fallbackIntent.getAction(), is(Intent.ACTION_VIEW));
assertThat(fallbackIntent.getData(), is(uri));
assertThat(fallbackIntent, hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY));
assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(false));
assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(false));
}
示例11: without_predicate_accept_any_value_immediately
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void without_predicate_accept_any_value_immediately() throws Exception {
WaitFunction<Void, String>
waitFunction =
(WaitFunction<Void, String>) WaitFunction
.waitFor(new Function<Void, String>() {
@Override
public String apply(Void input) {
return testName.getMethodName();
}
})
.get();
WaitFunction<Void, String> spy = Mockito.spy(waitFunction);
String result = spy.apply(null);
assertThat(result, Matchers.equalTo(testName.getMethodName()));
// Sleep not expected because of immediate success.
Mockito.verify(spy, VerificationModeFactory.atMost(0)).sleep(Mockito.anyLong());
}
示例12: testSubscriptionSuccess
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
public void testSubscriptionSuccess() throws InterruptedException {
final MarketDataInjectorImpl overrideInjector = new MarketDataInjectorImpl();
final MockMarketDataProvider p1 = new MockMarketDataProvider("p1", true, 1);
final MarketDataProviderWithOverride provider = new MarketDataProviderWithOverride(p1, overrideInjector);
final MarketDataListener listener = mock(MarketDataListener.class);
provider.addListener(listener);
final ValueSpecification spec = getSpecification(1);
provider.subscribe(spec);
p1.awaitSubscriptionResponses();
verify(listener).subscriptionsSucceeded(Collections.singleton(spec));
verify(listener, VerificationModeFactory.noMoreInteractions()).subscriptionsSucceeded(Collections.singleton(Mockito.<ValueSpecification>anyObject()));
p1.valuesChanged(Collections.singleton(spec));
verify(listener, VerificationModeFactory.times(1)).valuesChanged(Collections.singleton(spec));
}
示例13: testProjectOpenedEvent_RiderVsts
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testProjectOpenedEvent_RiderVsts() {
when(applicationNamesInfo.getProductName()).thenReturn(IdeaHelper.RIDER_PRODUCT_NAME);
PowerMockito.mockStatic(ApplicationNamesInfo.class);
when(ApplicationNamesInfo.getInstance()).thenReturn(applicationNamesInfo);
when(VcsHelper.isVstsRepo(project)).thenReturn(true);
StatusBarManager.setupStatusBar();
Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
EventContextHelper.setProject(map, project);
ServerEventManager.getInstance().triggerAllEvents(map);
verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
buildStatusLookupOperation.onLookupStarted();
buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());
}
示例14: testRepoChangedEvent_afterProjectOpened
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test
public void testRepoChangedEvent_afterProjectOpened() {
StatusBarManager.setupStatusBar();
Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
EventContextHelper.setProject(map, project);
ServerEventManager.getInstance().triggerAllEvents(map);
verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
buildStatusLookupOperation.onLookupStarted();
buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());
// Now close the project
Map<String, Object> map2 = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_CLOSING);
EventContextHelper.setProject(map2, project);
ServerEventManager.getInstance().triggerAllEvents(map2);
verify(statusBar, VerificationModeFactory.times(1)).removeWidget(anyString());
}
示例15: testConnectionClose
import org.mockito.internal.verification.VerificationModeFactory; //导入依赖的package包/类
@Test public void testConnectionClose() throws Exception {
final ConnectionImpl mmConn = TestConnection.getMMConnection();
XAConnectionImpl xaConn = new XAConnectionImpl(mmConn);
Connection conn = xaConn.getConnection();
StatementImpl stmt = (StatementImpl)conn.createStatement();
conn.setAutoCommit(false);
conn.close();
ServerConnection sc = xaConn.getConnectionImpl().getServerConnection();
Mockito.verify(sc, VerificationModeFactory.times(1)).cleanUp();
assertTrue(stmt.isClosed());
assertTrue(conn.getAutoCommit());
conn = xaConn.getConnection();
stmt = (StatementImpl)conn.createStatement();
XAResource resource = xaConn.getXAResource();
resource.start(new XidImpl(1, new byte[0], new byte[0]), XAResource.TMNOFLAGS);
conn.close();
assertTrue(stmt.isClosed());
assertTrue(conn.getAutoCommit());
}