/** * see original {@link Mockito#doCallRealMethod()} * @since 1.8.0 */ public static BDDStubber willCallRealMethod() { return new BDDStubberImpl(Mockito.doCallRealMethod()); } }
/** * see original {@link Mockito#doCallRealMethod()} * @since 1.8.0 */ public static BDDStubber willCallRealMethod() { return new BDDStubberImpl(Mockito.doCallRealMethod()); } }
@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(); }
@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(); }
@Before public void setup() { conf = HBaseConfiguration.create(); master = mock(HMaster.class); doCallRealMethod().when(master).updateConfigurationForQuotasObserver( any()); }
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; }
@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)); }
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; }
@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(); }
@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 ); }
@Test( expected = IllegalArgumentException.class ) public void setServletReponseTest() { Trans transMock = mock( Trans.class ); doCallRealMethod().when( transMock ).setServletReponse( null ); transMock.setServletReponse( null ); }
@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 ); }
@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(); } }
@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(); } }
@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 ); }
@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() ); }
@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() ); }
@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() ); }
@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() ); }
@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 ); }