本文整理了Java中org.mockito.Mockito.same()
方法的一些代码示例,展示了Mockito.same()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.same()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:same
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void afterConnectionClosed() {
this.session.afterConnectionClosed();
verify(this.sessionHandler).handleTransportError(same(this.session), any(ConnectionLostException.class));
verifyNoMoreInteractions(this.sessionHandler);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void webSocketHandshakeFailure() throws Exception {
connect();
IllegalStateException handshakeFailure = new IllegalStateException("simulated exception");
this.handshakeFuture.setException(handshakeFailure);
verify(this.stompSession).afterConnectFailure(same(handshakeFailure));
}
代码示例来源:origin: cloudfoundry/uaa
private void checkValidationForModes(IdentityZone zone, IdentityZoneConfiguration config) throws InvalidIdentityZoneConfigurationException, InvalidIdentityZoneDetailsException {
for (IdentityZoneValidator.Mode mode : Arrays.asList(CREATE, MODIFY, DELETE)) {
reset(zoneConfigurationValidator);
when(zoneConfigurationValidator.validate(any(), any())).thenReturn(config);
validator.validate(zone, mode);
verify(zoneConfigurationValidator, times(1)).validate(same(zone), same(mode));
}
}
}
代码示例来源:origin: apache/usergrid
/** Standard flow */
@Test
public void testStartStage() throws Exception {
final ApplicationScope context = mock( ApplicationScope.class );
//mock returning a mock mutation when we do a log entry write
final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
final ArgumentCaptor<MvccLogEntry> logEntry = ArgumentCaptor.forClass( MvccLogEntry.class );
final MutationBatch mutation = mock( MutationBatch.class );
final UUIDService uuidService = mock ( UUIDService.class );
when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( mutation );
//set up the mock to return the entity from the start phase
final Entity entity = TestEntityGenerator.generateEntity();
//run the stage
WriteStart newStage = new WriteStart( logStrategy);
//verify the observable is correct
CollectionIoEvent<MvccEntity> result = newStage.call( new CollectionIoEvent<Entity>( context, entity ) );
//verify the log entry is correct
MvccLogEntry entry = logEntry.getValue();
assertEquals( "id correct", entity.getId(), entry.getEntityId() );
assertEquals( "EventStage is correct", Stage.ACTIVE, entry.getStage() );
MvccEntity created = result.getEvent();
//verify uuid and version in both the MvccEntity and the entity itself
//assertSame is used on purpose. We want to make sure the same instance is used, not a copy.
//this way the caller's runtime type is retained.
assertSame( "id correct", entity.getId(), created.getId() );
assertSame( "Entity correct", entity, created.getEntity().get() );
}
代码示例来源:origin: apache/geode
private void givenOldRegionEntry() {
when(entryMap.get(eq(key))).thenReturn(null);
when(regionEntryFactory.createEntry(any(), any(), any())).thenReturn(factoryRegionEntry);
when(entryMap.putIfAbsent(eq(key), same(factoryRegionEntry))).thenReturn(oldRegionEntry);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleMessageBadData() throws Exception {
TextMessage message = new TextMessage("[\"x]");
this.session.handleMessage(message, this.webSocketSession);
this.session.isClosed();
verify(this.webSocketHandler).handleTransportError(same(this.session), any(IOException.class));
verifyNoMoreInteractions(this.webSocketHandler);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void webSocketTransportError() throws Exception {
IllegalStateException exception = new IllegalStateException("simulated exception");
connect().handleTransportError(this.webSocketSession, exception);
verify(this.stompSession).handleFailure(same(exception));
}
代码示例来源:origin: apache/usergrid
@Test
public void testStartStage() throws Exception {
when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( logMutation );
when( mvccEntityStrategy.write( same( context ), mvccEntityCapture.capture() ) )
.thenReturn( mvccEntityMutation );
代码示例来源:origin: it.tidalwave.northernwind/it-tidalwave-northernwind-core-default
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Test
public void createViewAndController_must_delegate_to_the_proper_ViewBuilder()
throws Exception
{
final ViewBuilder viewBuilder = mock(ViewBuilder.class);
final SiteNode siteNode = mock(SiteNode.class);
final Id id = new Id("theId");
final ViewAndController viewAndController = mock(ViewAndController.class);
when(viewBuilder.createViewAndController(eq(id), same(siteNode))).thenReturn(viewAndController);
underTest.viewBuilderMapByTypeUri.put("type1", viewBuilder);
final ViewAndController vac = underTest.createViewAndController("type1", id, siteNode);
verify(viewBuilder).createViewAndController(eq(id), same(siteNode));
assertThat(vac, is(sameInstance(viewAndController)));
}
代码示例来源:origin: info.magnolia/magnolia-i18n
private void setupTranslationServiceWith(String expectedKey, String desiredResult) {
when(translationService.translate(same(localeProvider), eq(new String[]{expectedKey}))).thenReturn(desiredResult);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleErrorFrameWithConversionException() {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
accessor.addNativeHeader("foo", "bar");
accessor.setLeaveMutable(true);
byte[] payload = "{'foo':'bar'}".getBytes(StandardCharsets.UTF_8);
StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
when(this.sessionHandler.getPayloadType(stompHeaders)).thenReturn(Map.class);
this.session.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
verify(this.sessionHandler).getPayloadType(stompHeaders);
verify(this.sessionHandler).handleException(same(this.session), same(StompCommand.ERROR),
eq(stompHeaders), same(payload), any(MessageConversionException.class));
verifyNoMoreInteractions(this.sessionHandler);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = LOLLIPOP)
public void formatChangeReported() {
verify(callback).onOutputFormatChanged(same(codec), any());
}
代码示例来源:origin: apache/usergrid
@Test
public void testStartStage() throws Exception {
when( logStrategy.write( same( context ), logEntry.capture() ) ).thenReturn( logMutation );
when( mvccEntityStrategy.write( same( context ), mvccEntityCapture.capture() ) )
.thenReturn( mvccEntityMutation );
代码示例来源:origin: line/centraldogma
@Test
public void operationsAreCalledInOrder() {
final JsonNode node1 = FACTORY.textNode("hello");
final JsonNode node2 = FACTORY.textNode("world");
when(op1.apply(node1)).thenReturn(node2);
final JsonPatch patch = new JsonPatch(ImmutableList.of(op1, op2));
final ArgumentCaptor<JsonNode> captor = ArgumentCaptor.forClass(JsonNode.class);
patch.apply(node1);
verify(op1, only()).apply(same(node1));
verify(op2, only()).apply(captor.capture());
assertSame(captor.getValue(), node2);
}
代码示例来源:origin: it.tidalwave.northernwind/it-tidalwave-northernwind-frontend-media
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Test
public void must_return_the_interpolated_string_when_metadata_is_found()
throws Exception
{
final Metadata metadata = mock(Metadata.class);
when(metadata.interpolateString(anyString(), same(siteNodeProperties))).thenReturn("result");
when(metadataCache.findMetadataById(eq(mediaId), same(siteNodeProperties))).thenReturn(metadata);
final String result = underTest.getMetadataString(mediaId, "template", siteNodeProperties);
assertThat(result, is("result"));
}
代码示例来源:origin: apache/geode
@Test
public void mapDataSourceWithGetConnectionSuccessClosesConnectionAndRebinds() throws Exception {
Map<String, String> inputs = new HashMap<>();
Context context = mock(Context.class);
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
when(dataSource.getConnection()).thenReturn(connection);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
when(dataSourceFactory.getSimpleDataSource(any())).thenReturn(dataSource);
inputs.put("type", "SimpleDataSource");
String jndiName = "myJndiBinding";
inputs.put("jndi-name", jndiName);
JNDIInvoker.mapDatasource(inputs, null, dataSourceFactory, context);
verify(connection).close();
verify(context).rebind((String) any(), same(dataSource));
}
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = LOLLIPOP)
public void presentsInputBuffer() {
verify(callback).onInputBufferAvailable(same(codec), anyInt());
}
代码示例来源:origin: modcluster/mod_cluster
@Test
public void findHost() {
org.apache.catalina.Host host = mock(org.apache.catalina.Host.class);
HostFactory hostFactory = mock(HostFactory.class);
Host expected = mock(Host.class);
when(this.engine.findChild("host")).thenReturn(host);
when(this.registry.getHostFactory()).thenReturn(hostFactory);
when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected);
Host result = this.catalinaEngine.findHost("host");
assertSame(expected, result);
}
代码示例来源:origin: java-json-tools/json-schema-core
@Test
public void noFailureDoesNotTriggerEarlyExit()
throws ProcessingException
{
@SuppressWarnings("unchecked")
final Processor<MessageProvider, MessageProvider> p1
= mock(Processor.class);
@SuppressWarnings("unchecked")
final Processor<MessageProvider, MessageProvider> p2
= mock(Processor.class);
final Processor<MessageProvider, MessageProvider> processor
= ProcessorChain.startWith(p1).failOnError().chainWith(p2)
.getProcessor();
final MessageProvider input = mock(MessageProvider.class);
final ProcessingReport report = new DummyReport(LogLevel.DEBUG);
when(p1.process(report, input)).thenReturn(input);
processor.process(report, input);
verify(p1).process(same(report), any(MessageProvider.class));
verify(p2).process(same(report), any(MessageProvider.class));
}
代码示例来源:origin: arquillian/arquillian-core
@Before
public void setup() throws Exception {
Mockito.when(serviceLoader.onlyOne(Mockito.same(DeployableContainer.class))).thenReturn(deployableContainer);
Mockito.when(deployableContainer.getConfigurationClass()).thenReturn(DummyContainerConfiguration.class);
}
内容来源于网络,如有侵权,请联系作者删除!