本文整理了Java中org.mockito.Mockito.doCallRealMethod()
方法的一些代码示例,展示了Mockito.doCallRealMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.doCallRealMethod()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:doCallRealMethod
[英]Use doCallRealMethod()
when you want to call the real implementation of a method.
As usual you are going to read the partial mock warning: Object oriented programming is more less tackling complexity by dividing the complexity into separate, specific, SRPy objects. How does partial mock fit into this paradigm? Well, it just doesn't... Partial mock usually means that the complexity has been moved to a different method on the same object. In most cases, this is not the way you want to design your application.
However, there are rare cases when partial mocks come handy: dealing with code you cannot change easily (3rd party interfaces, interim refactoring of legacy code etc.) However, I wouldn't use partial mocks for new, test-driven & well-designed code.
See also javadoc Mockito#spy(Object) to find out more about partial mocks. Mockito.spy() is a recommended way of creating partial mocks. The reason is it guarantees real methods are called against correctly constructed object because you're responsible for constructing the object passed to spy() method.
Example:
Foo mock = mock(Foo.class);
doCallRealMethod().when(mock).someVoidMethod();
// this will call the real implementation of Foo.someVoidMethod()
mock.someVoidMethod();
See examples in javadoc for Mockito class
[中]
代码示例来源:origin: org.mockito/mockito-core
/**
* see original {@link Mockito#doCallRealMethod()}
* @since 1.8.0
*/
public static BDDStubber willCallRealMethod() {
return new BDDStubberImpl(Mockito.doCallRealMethod());
}
}
代码示例来源:origin: google/j2objc
/**
* see original {@link Mockito#doCallRealMethod()}
* @since 1.8.0
*/
public static BDDStubber willCallRealMethod() {
return new BDDStubberImpl(Mockito.doCallRealMethod());
}
}
代码示例来源:origin: square/picasso
@Test
public void cancelNotOnMainThreadCrashes() throws InterruptedException {
doCallRealMethod().when(picasso).cancelRequest(any(BitmapTarget.class));
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override public void run() {
try {
new RequestCreator(picasso, null, 0).into(mockTarget());
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ignored) {
} finally {
latch.countDown();
}
}
}).start();
latch.await();
}
代码示例来源:origin: square/picasso
@Test
public void intoNotOnMainThreadCrashes() throws InterruptedException {
doCallRealMethod().when(picasso).enqueueAndSubmit(any(Action.class));
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override public void run() {
try {
new RequestCreator(picasso, URI_1, 0).into(mockImageViewTarget());
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ignored) {
} finally {
latch.countDown();
}
}
}).start();
latch.await();
}
代码示例来源:origin: apache/hbase
@Before
public void setup() {
conf = HBaseConfiguration.create();
master = mock(HMaster.class);
doCallRealMethod().when(master).updateConfigurationForQuotasObserver(
any());
}
代码示例来源:origin: pentaho/pentaho-kettle
private NullIfMeta mockProcessRowMeta() throws KettleStepException {
NullIfMeta processRowMeta = smh.processRowsStepMetaInterface;
Field[] fields = createArrayWithOneField( "nullable-field", "nullable-value" );
doReturn( fields ).when( processRowMeta ).getFields();
doCallRealMethod().when( processRowMeta ).getFields( any( RowMetaInterface.class ), anyString(),
any( RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ),
any( IMetaStore.class ) );
return processRowMeta;
}
代码示例来源:origin: apache/kafka
@Test
@SuppressWarnings("deprecation")
public void testCloseWithTimeUnit() {
KafkaConsumer consumer = mock(KafkaConsumer.class);
doCallRealMethod().when(consumer).close(anyLong(), any());
consumer.close(1, TimeUnit.SECONDS);
verify(consumer).close(Duration.ofSeconds(1));
}
代码示例来源:origin: pentaho/pentaho-kettle
private IfNullMeta mockProcessRowMeta() throws KettleStepException {
IfNullMeta processRowMeta = smh.processRowsStepMetaInterface;
doReturn( createFields( "null-field", "empty-field", "space-field" ) ).when( processRowMeta ).getFields();
doReturn( "replace-value" ).when( processRowMeta ).getReplaceAllByValue();
doCallRealMethod().when( processRowMeta ).getFields( any( RowMetaInterface.class ), anyString(), any(
RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ), any(
IMetaStore.class ) );
return processRowMeta;
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldSpawnTouchLoopOnSet() throws IOException {
Lockfile lockfile = mock(Lockfile.class);
doCallRealMethod().when(lockfile).setHooks();
doNothing().when(lockfile).touch();
doNothing().when(lockfile).spawnTouchLoop();
lockfile.setHooks();
verify(lockfile).spawnTouchLoop();
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test( timeout = 1000 )
public void testDrawTimeScaleLineInfinityLoop() {
GCInterface gCInterfaceMock = mock( GCInterface.class );
when( metricsPainter.getGc() ).thenReturn( gCInterfaceMock );
doCallRealMethod().when( metricsPainter ).drawTimeScaleLine( heightStub, pixelsPerMsStub, periodInMsStub );
when( gCInterfaceMock.textExtent( anyString() ) ).thenReturn( mock( Point.class ) );
metricsPainter.drawTimeScaleLine( heightStub, pixelsPerMsStub, periodInMsStub );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test( expected = IllegalArgumentException.class )
public void setServletReponseTest() {
Trans transMock = mock( Trans.class );
doCallRealMethod().when( transMock ).setServletReponse( null );
transMock.setServletReponse( null );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testReplace() {
String input = "\\\"Name\"";
String[] from = new String[] { "\"" };
String[] to = new String[] { "\\\"" };
doCallRealMethod().when( ingresVectorwiseLoaderMock ).replace( anyString(), any( String[].class ),
any( String[].class ) );
String actual = ingresVectorwiseLoaderMock.replace( input, from, to );
String expected = "\\\\\"Name\\\"";
assertEquals( actual, expected );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testSimpleMappingStep() throws KettleException {
when( stepMock.getData() ).thenReturn( stepDataMock );
when( stepDataMock.getMappingTrans() ).thenReturn( transMock );
// stubbing methods for null-checking
when( stepMock.getTrans() ).thenReturn( transMock );
when( transMock.getServletResponse() ).thenReturn( null );
doThrow( new RuntimeException( "The getServletResponse() mustn't be executed!" ) ).when( transMock )
.setServletReponse( any( HttpServletResponse.class ) );
doCallRealMethod().when( stepMock ).initServletConfig();
stepMock.initServletConfig();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testMappingStep() throws KettleException {
when( stepMock.getData() ).thenReturn( stepDataMock );
when( stepDataMock.getMappingTrans() ).thenReturn( transMock );
// stubbing methods for null-checking
when( stepMock.getTrans() ).thenReturn( transMock );
when( transMock.getServletResponse() ).thenReturn( null );
doThrow( new RuntimeException( "The getServletResponse() mustn't be executed!" ) ).when( transMock )
.setServletReponse( any( HttpServletResponse.class ) );
doCallRealMethod().when( stepMock ).initServletConfig();
stepMock.initServletConfig();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void recordsCleanUpMethodIsCalled_JobLogTable() throws Exception {
JobLogTable jobLogTable = JobLogTable.getDefault( mockedVariableSpace, hasDatabasesInterface );
setAllTableParamsDefault( jobLogTable );
doCallRealMethod().when( mockedJob ).writeLogTableInformation( jobLogTable, LogStatus.END );
mockedJob.writeLogTableInformation( jobLogTable, LogStatus.END );
verify( mockedDataBase ).cleanupLogRecords( jobLogTable );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void thirdStreamIsExecutionResultFiles() throws Exception {
StreamInterface stream = mockStream();
StepIOMetaInterface stepIo = mockStepIo( stream, 2 );
TransExecutorMeta meta = new TransExecutorMeta();
meta = spy( meta );
when( meta.getStepIOMeta() ).thenReturn( stepIo );
doCallRealMethod().when( meta ).handleStreamSelection( any( StreamInterface.class ) );
meta.handleStreamSelection( stream );
assertEquals( stream.getStepMeta(), meta.getResultFilesTargetStepMeta() );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void firstStreamIsExecutionStatistics() throws Exception {
StreamInterface stream = mockStream();
StepIOMetaInterface stepIo = mockStepIo( stream, 0 );
TransExecutorMeta meta = new TransExecutorMeta();
meta = spy( meta );
when( meta.getStepIOMeta() ).thenReturn( stepIo );
doCallRealMethod().when( meta ).handleStreamSelection( any( StreamInterface.class ) );
meta.handleStreamSelection( stream );
assertEquals( stream.getStepMeta(), meta.getExecutionResultTargetStepMeta() );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void secondStreamIsInternalTransformationsOutput() throws Exception {
StreamInterface stream = mockStream();
StepIOMetaInterface stepIo = mockStepIo( stream, 1 );
TransExecutorMeta meta = new TransExecutorMeta();
meta = spy( meta );
when( meta.getStepIOMeta() ).thenReturn( stepIo );
doCallRealMethod().when( meta ).handleStreamSelection( any( StreamInterface.class ) );
meta.handleStreamSelection( stream );
assertEquals( stream.getStepMeta(), meta.getOutputRowsSourceStepMeta() );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void forthStreamIsExecutorsInput() throws Exception {
StreamInterface stream = mockStream();
StepIOMetaInterface stepIo = mockStepIo( stream, 3 );
TransExecutorMeta meta = new TransExecutorMeta();
meta = spy( meta );
when( meta.getStepIOMeta() ).thenReturn( stepIo );
doCallRealMethod().when( meta ).handleStreamSelection( any( StreamInterface.class ) );
meta.handleStreamSelection( stream );
assertEquals( stream.getStepMeta(), meta.getExecutorsOutputStepMeta() );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void recordsCleanUpMethodIsCalled_JobEntryLogTable() throws Exception {
JobEntryLogTable jobEntryLogTable = JobEntryLogTable.getDefault( mockedVariableSpace, hasDatabasesInterface );
setAllTableParamsDefault( jobEntryLogTable );
JobMeta jobMeta = new JobMeta( );
jobMeta.setJobEntryLogTable( jobEntryLogTable );
when( mockedJob.getJobMeta() ).thenReturn( jobMeta );
doCallRealMethod().when( mockedJob ).writeJobEntryLogInformation();
mockedJob.writeJobEntryLogInformation();
verify( mockedDataBase ).cleanupLogRecords( jobEntryLogTable );
}
内容来源于网络,如有侵权,请联系作者删除!