### Question:
DatabaseJoin extends BaseTransform<DatabaseJoinMeta, DatabaseJoinData> implements ITransform<DatabaseJoinMeta, DatabaseJoinData> { public synchronized void stopRunning() throws HopException { if ( this.isStopped() || data.isDisposed() ) { return; } if ( data.db != null && data.db.getConnection() != null && !data.isCanceled ) { data.db.cancelStatement( data.pstmt ); setStopped( true ); data.isCanceled = true; } } DatabaseJoin( TransformMeta transformMeta, DatabaseJoinMeta meta, DatabaseJoinData data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline ); boolean processRow(); synchronized void stopRunning(); boolean init(); void dispose();  }### Answer:
@Test public void testStopRunningWhenTransformIsStopped() throws HopException { doReturn( true ).when( mockDatabaseJoin ).isStopped(); mockDatabaseJoin.stopRunning(); verify( mockDatabaseJoin, times( 1 ) ).isStopped(); verify( mockTransformDataInterface, times( 0 ) ).isDisposed(); }
@Test public void testStopRunningWhenTransformDataInterfaceIsDisposed() throws HopException { doReturn( false ).when( mockDatabaseJoin ).isStopped(); doReturn( true ).when( mockTransformDataInterface ).isDisposed(); mockDatabaseJoin.stopRunning(); verify( mockDatabaseJoin, times( 1 ) ).isStopped(); verify( mockTransformDataInterface, times( 1 ) ).isDisposed(); }
@Test public void testStopRunningWhenTransformIsNotStoppedNorTransformDataInterfaceIsDisposedAndDatabaseConnectionIsValid() throws HopException { doReturn( false ).when( mockDatabaseJoin ).isStopped(); doReturn( false ).when( mockTransformDataInterface ).isDisposed(); when( mockTransformDataInterface.db.getConnection() ).thenReturn( mock( Connection.class ) ); mockDatabaseJoin.stopRunning(); verify( mockDatabaseJoin, times( 1 ) ).isStopped(); verify( mockTransformDataInterface, times( 1 ) ).isDisposed(); verify( mockTransformDataInterface.db, times( 1 ) ).getConnection(); verify( mockTransformDataInterface.db, times( 1 ) ).cancelStatement( any( PreparedStatement.class ) ); assertTrue( mockTransformDataInterface.isCanceled ); }
@Test public void testStopRunningWhenTransformIsNotStoppedNorTransformDataInterfaceIsDisposedAndDatabaseConnectionIsNotValid() throws HopException { doReturn( false ).when( mockDatabaseJoin ).isStopped(); doReturn( false ).when( mockTransformDataInterface ).isDisposed(); when( mockTransformDataInterface.db.getConnection() ).thenReturn( null ); mockDatabaseJoin.stopRunning(); verify( mockDatabaseJoin, times( 1 ) ).isStopped(); verify( mockTransformDataInterface, times( 1 ) ).isDisposed(); verify( mockTransformDataInterface.db, times( 1 ) ).getConnection(); verify( mockTransformDataInterface.db, times( 0 ) ).cancelStatement( any( PreparedStatement.class ) ); assertFalse( mockTransformDataInterface.isCanceled ); }