method2testcases
stringlengths
118
3.08k
### Question: DatabaseUtil implements DataSourceProviderInterface { @Override public DataSource getNamedDataSource( String datasourceName ) throws DataSourceNamingException { ClassLoader original = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( getClass().getClassLoader() ); return DatabaseUtil.getDataSourceFromJndi( datasourceName, new InitialContext() ); } catch ( NamingException ex ) { throw new DataSourceNamingException( ex ); } finally { Thread.currentThread().setContextClassLoader( original ); } } static void closeSilently( Connection[] connections ); static void closeSilently( Connection conn ); static void closeSilently( Statement[] statements ); static void closeSilently( Statement st ); @Override DataSource getNamedDataSource( String datasourceName ); @Override DataSource getNamedDataSource( String datasourceName, DatasourceType type ); }### Answer: @Test public void testCl() throws NamingException { DataSource dataSource = mock( DataSource.class ); when( context.lookup( testName ) ).thenReturn( dataSource ); DatabaseUtil util = new DatabaseUtil(); ClassLoader orig = Thread.currentThread().getContextClassLoader(); ClassLoader cl = mock( ClassLoader.class ); try { Thread.currentThread().setContextClassLoader( cl ); util.getNamedDataSource( testName ); } catch ( Exception ex ) { } finally { try { verify( cl, never() ).loadClass( anyString() ); verify( cl, never() ).getResource( anyString() ); verify( cl, never() ).getResourceAsStream( anyString() ); } catch ( Exception ex ) { } Thread.currentThread().setContextClassLoader( orig ); } }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public int getDefaultDatabasePort() { if ( getAccessType() == DatabaseMeta.TYPE_ACCESS_NATIVE ) { return 5439; } return -1; } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testGetDefaultDatabasePort() throws Exception { assertEquals( 5439, dbMeta.getDefaultDatabasePort() ); dbMeta.setAccessType( DatabaseMeta.TYPE_ACCESS_JNDI ); assertEquals( -1, dbMeta.getDefaultDatabasePort() ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public String getDriverClass() { if ( getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC ) { return "sun.jdbc.odbc.JdbcOdbcDriver"; } else { return "com.amazon.redshift.jdbc4.Driver"; } } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testGetDriverClass() throws Exception { assertEquals( "com.amazon.redshift.jdbc4.Driver", dbMeta.getDriverClass() ); dbMeta.setAccessType( DatabaseMeta.TYPE_ACCESS_ODBC ); assertEquals( "sun.jdbc.odbc.JdbcOdbcDriver", dbMeta.getDriverClass() ); }
### Question: MessageEventService { public final void addHandler( final Message eventType, final MessageEventHandler handler ) throws HandlerRegistrationException { if ( handler != null && eventType != null ) { addHandlerFor( eventType, handler ); } else { throw new HandlerRegistrationException( "One of the parameters is null : " + " eventType: " + eventType + " handler:" + handler ); } } MessageEventService(); void fireEvent( final Message event ); final void addHandler( final Message eventType, final MessageEventHandler handler ); final boolean hasHandlers( final Message eventType ); List<MessageEventHandler> getHandlersFor( final Message eventType ); }### Answer: @Test( expected = HandlerRegistrationException.class ) public void testTranformationDuplicateAddHandler() throws KettleException { messageEventService.addHandler( transformationMessageEvent, messageEventHandler ); messageEventService.addHandler( transformationMessageEvent, messageEventHandler ); } @Test( expected = HandlerRegistrationException.class ) public void testOperationDuplicateAddHandler() throws KettleException { messageEventService.addHandler( operationMessageEvent, messageEventHandler ); messageEventService.addHandler( operationMessageEvent, messageEventHandler ); } @Test( expected = HandlerRegistrationException.class ) public void testMsgEventTypeNull() throws KettleException { messageEventService.addHandler( null, messageEventHandler ); } @Test( expected = HandlerRegistrationException.class ) public void testMsgHandlerNull() throws KettleException { messageEventService.addHandler( operationMessageEvent, null ); } @Test( expected = HandlerRegistrationException.class ) public void testbothNull() throws KettleException { messageEventService.addHandler( null, null ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public String getURL( String hostname, String port, String databaseName ) { if ( getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC ) { return "jdbc:odbc:" + databaseName; } else { return "jdbc:redshift: } } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testGetURL() throws Exception { assertEquals( "jdbc:redshift: assertEquals( "jdbc:redshift: dbMeta.getURL( "rs.pentaho.com", "4444", "myDB" ) ); dbMeta.setAccessType( DatabaseMeta.TYPE_ACCESS_ODBC ); assertEquals( "jdbc:odbc:myDB", dbMeta.getURL( null, "Not Null", "myDB" ) ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public String getExtraOptionsHelpText() { return "http: } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testGetExtraOptionsHelpText() throws Exception { assertEquals( "http: dbMeta.getExtraOptionsHelpText() ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public boolean isFetchSizeSupported() { return false; } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testIsFetchSizeSupported() throws Exception { assertFalse( dbMeta.isFetchSizeSupported() ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public boolean supportsSetMaxRows() { return false; } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testSupportsSetMaxRows() throws Exception { assertFalse( dbMeta.supportsSetMaxRows() ); }
### Question: RedshiftDatabaseMeta extends PostgreSQLDatabaseMeta { @Override public String[] getUsedLibraries() { return new String[] { "RedshiftJDBC4_1.0.10.1010.jar" }; } RedshiftDatabaseMeta(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override String getExtraOptionsHelpText(); @Override boolean isFetchSizeSupported(); @Override boolean supportsSetMaxRows(); @Override String[] getUsedLibraries(); }### Answer: @Test public void testGetUsedLibraries() throws Exception { String[] libs = dbMeta.getUsedLibraries(); assertNotNull( libs ); assertEquals( 1, libs.length ); assertEquals( "RedshiftJDBC4_1.0.10.1010.jar", libs[0] ); }
### Question: MessageEventService { public final boolean hasHandlers( final Message eventType ) { return containsHandlerFor( eventType ); } MessageEventService(); void fireEvent( final Message event ); final void addHandler( final Message eventType, final MessageEventHandler handler ); final boolean hasHandlers( final Message eventType ); List<MessageEventHandler> getHandlersFor( final Message eventType ); }### Answer: @Test public void testTransformationHasHandler() throws KettleException { addHandlers( transformationMessageEvent, messageEventHandler, messageEventHandler2 ); assertTrue( messageEventService.hasHandlers( transformationMessageEvent ) ); } @Test public void testTransformationHasHandlerFalseTrans() throws KettleException { addHandlers( transformationMessageEvent, messageEventHandler, messageEventHandler2 ); assertFalse( messageEventService.hasHandlers( otherTransMessageEvent ) ); } @Test public void testTransformationHasHandlerFalseOp() throws KettleException { addHandlers( transformationMessageEvent, messageEventHandler, messageEventHandler2 ); assertFalse( messageEventService.hasHandlers( otherOpMessageEvent ) ); } @Test public void testOperationHasHandler() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); assertTrue( messageEventService.hasHandlers( operationMessageEvent ) ); } @Test public void testOperationHasHandlerFalseTrans() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); assertFalse( messageEventService.hasHandlers( otherTransMessageEvent ) ); } @Test public void testOperationHasHandlerFalseOp() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); assertFalse( messageEventService.hasHandlers( otherOpMessageEvent ) ); }
### Question: HypersonicDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getSQLSequenceExists( String sequenceName ) { return "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = '" + sequenceName + "'"; } @Override int[] getAccessTypeList(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override boolean supportsBitmapIndex(); @Override String getAddColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ); @Override String[] getUsedLibraries(); @Override String getExtraOptionsHelpText(); @Override String[] getReservedWords(); @Override boolean supportsSequences(); @Override String getSQLSequenceExists( String sequenceName ); @Override String getSQLListOfSequences(); @Override String getSQLCurrentSequenceValue( String sequenceName ); @Override String getSQLNextSequenceValue( String sequenceName ); }### Answer: @Test public void testGetSQLSequenceExists() throws Exception { String sql = hypersonicDatabaseMeta.getSQLSequenceExists( sequenceName ); String expectedSql = "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = 'seQuence'"; assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaQouting.getSQLSequenceExists( sequenceName ); assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaUppercase.getSQLSequenceExists( sequenceName ); assertEquals( expectedSql, sql ); }
### Question: HypersonicDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getSQLCurrentSequenceValue( String sequenceName ) { return "SELECT " + sequenceName + ".currval FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = '" + sequenceName + "'"; } @Override int[] getAccessTypeList(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override boolean supportsBitmapIndex(); @Override String getAddColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ); @Override String[] getUsedLibraries(); @Override String getExtraOptionsHelpText(); @Override String[] getReservedWords(); @Override boolean supportsSequences(); @Override String getSQLSequenceExists( String sequenceName ); @Override String getSQLListOfSequences(); @Override String getSQLCurrentSequenceValue( String sequenceName ); @Override String getSQLNextSequenceValue( String sequenceName ); }### Answer: @Test public void testGetSQLCurrentSequenceValue() throws Exception { String sql = hypersonicDatabaseMeta.getSQLCurrentSequenceValue( sequenceName ); String expectedSql = "SELECT seQuence.currval FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = 'seQuence'"; assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaQouting.getSQLCurrentSequenceValue( sequenceName ); assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaUppercase.getSQLCurrentSequenceValue( sequenceName ); assertEquals( expectedSql, sql ); }
### Question: HypersonicDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface { @Override public String getSQLNextSequenceValue( String sequenceName ) { return "SELECT NEXT VALUE FOR " + sequenceName + " FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = '" + sequenceName + "'"; } @Override int[] getAccessTypeList(); @Override int getDefaultDatabasePort(); @Override String getDriverClass(); @Override String getURL( String hostname, String port, String databaseName ); @Override boolean supportsBitmapIndex(); @Override String getAddColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc, String pk, boolean semicolon ); @Override String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ); @Override String[] getUsedLibraries(); @Override String getExtraOptionsHelpText(); @Override String[] getReservedWords(); @Override boolean supportsSequences(); @Override String getSQLSequenceExists( String sequenceName ); @Override String getSQLListOfSequences(); @Override String getSQLCurrentSequenceValue( String sequenceName ); @Override String getSQLNextSequenceValue( String sequenceName ); }### Answer: @Test public void testGetSQLNextSequenceValue() throws Exception { String sql = hypersonicDatabaseMeta.getSQLNextSequenceValue( sequenceName ); String expectedSql = "SELECT NEXT VALUE FOR seQuence FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = 'seQuence'"; assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaQouting.getSQLNextSequenceValue( sequenceName ); assertEquals( expectedSql, sql ); sql = hypersonicDatabaseMetaUppercase.getSQLNextSequenceValue( sequenceName ); assertEquals( expectedSql, sql ); }
### Question: InfobrightDatabaseMeta extends MySQLDatabaseMeta implements DatabaseInterface { @Override public int getDefaultDatabasePort() { if ( getAccessType() == DatabaseMeta.TYPE_ACCESS_NATIVE ) { return 5029; } return -1; } @Override int getDefaultDatabasePort(); @Override void addDefaultOptions(); }### Answer: @Test public void mysqlTestOverrides() throws Exception { InfobrightDatabaseMeta idm = new InfobrightDatabaseMeta(); idm.setAccessType( DatabaseMeta.TYPE_ACCESS_NATIVE ); assertEquals( 5029, idm.getDefaultDatabasePort() ); idm.setAccessType( DatabaseMeta.TYPE_ACCESS_ODBC ); assertEquals( -1, idm.getDefaultDatabasePort() ); }
### Question: SvgSupport { public static boolean isSvgEnabled() { return true; } static boolean isSvgEnabled(); static SvgImage loadSvgImage( InputStream in ); static boolean isSvgName( String name ); static String toPngName( String name ); static boolean isPngName( String name ); static String toSvgName( String name ); }### Answer: @Test public void testIsSvgEnabled() throws Exception { assertTrue( SvgSupport.isSvgEnabled() ); }
### Question: SvgSupport { public static SvgImage loadSvgImage( InputStream in ) throws Exception { Document document = getSvgFactory().createDocument( null, in ); return new SvgImage( document ); } static boolean isSvgEnabled(); static SvgImage loadSvgImage( InputStream in ); static boolean isSvgName( String name ); static String toPngName( String name ); static boolean isPngName( String name ); static String toSvgName( String name ); }### Answer: @Test public void testLoadSvgImage() throws Exception { SvgImage image = SvgSupport.loadSvgImage( new ByteArrayInputStream( svgImage.getBytes() ) ); assertNotNull( image ); }
### Question: DataHandler extends AbstractXulEventHandler { public void getOptionHelp() { String message = null; DatabaseMeta database = new DatabaseMeta(); getInfo( database ); String url = database.getExtraOptionsHelpText(); if ( ( url == null ) || ( url.trim().length() == 0 ) ) { message = Messages.getString( "DataHandler.USER_NO_HELP_AVAILABLE" ); showMessage( message, false ); return; } Status status = Launch.openURL( url ); if ( status.equals( Status.Failed ) ) { message = Messages.getString( "DataHandler.USER_UNABLE_TO_LAUNCH_BROWSER", url ); showMessage( message, false ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testGetOptionHelp() throws Exception { when( accessBox.getSelectedItem() ).thenReturn( "JNDI" ); when( connectionBox.getSelectedItem() ).thenReturn( "PostgreSQL" ); dataHandler.getOptionHelp(); } @Test( expected = RuntimeException.class ) public void testGetOptionHelpNoDatabase() throws Exception { when( accessBox.getSelectedItem() ).thenReturn( "JNDI" ); when( connectionBox.getSelectedItem() ).thenReturn( "MyDB" ); dataHandler.getOptionHelp(); }
### Question: SvgSupport { public static String toPngName( String name ) { if ( isSvgName( name ) ) { name = name.substring( 0, name.length() - 4 ) + PNG_EXTENSION; } return name; } static boolean isSvgEnabled(); static SvgImage loadSvgImage( InputStream in ); static boolean isSvgName( String name ); static String toPngName( String name ); static boolean isPngName( String name ); static String toSvgName( String name ); }### Answer: @Test public void testToPngName() throws Exception { assertTrue( SvgSupport.isPngName( "my_file.png" ) ); assertTrue( SvgSupport.isPngName( "my_file.PNG" ) ); assertTrue( SvgSupport.isPngName( ".png" ) ); assertFalse( SvgSupport.isPngName( "png" ) ); assertFalse( SvgSupport.isPngName( "myFile.svg" ) ); assertEquals( "myFile.png", SvgSupport.toPngName( "myFile.svg" ) ); }
### Question: SvgSupport { public static String toSvgName( String name ) { if ( isPngName( name ) ) { name = name.substring( 0, name.length() - 4 ) + SVG_EXTENSION; } return name; } static boolean isSvgEnabled(); static SvgImage loadSvgImage( InputStream in ); static boolean isSvgName( String name ); static String toPngName( String name ); static boolean isPngName( String name ); static String toSvgName( String name ); }### Answer: @Test public void testToSvgName() throws Exception { assertTrue( SvgSupport.isSvgName( "my_file.svg" ) ); assertTrue( SvgSupport.isSvgName( "my_file.SVG" ) ); assertTrue( SvgSupport.isSvgName( ".svg" ) ); assertFalse( SvgSupport.isSvgName( "svg" ) ); assertFalse( SvgSupport.isSvgName( "myFile.png" ) ); assertEquals( "myFile.svg", SvgSupport.toSvgName( "myFile.png" ) ); }
### Question: SvgImage { public Document getDocument() { return document; } protected SvgImage( Document doc ); Document getDocument(); }### Answer: @Test public void testGetDocument() throws Exception { assertEquals( document, image.getDocument() ); }
### Question: LogMessage implements LogMessageInterface { @Override @Deprecated public String toString() { if ( message == null ) { return subject; } if ( arguments != null && arguments.length > 0 ) { return subject + " - " + MessageFormat.format( message, arguments ); } else { return subject + " - " + message; } } LogMessage( String subject, LogLevel level ); LogMessage( String message, String logChannelId, LogLevel level ); LogMessage( String message, String logChannelId, Object[] arguments, LogLevel level ); @Override @Deprecated String toString(); @Override LogLevel getLevel(); @Deprecated void setLevel( LogLevel level ); @Override String getMessage(); @Deprecated void setMessage( String message ); @Override String getSubject(); @Deprecated void setSubject( String subject ); @Override String getLogChannelId(); @Deprecated void setLogChannelId( String logChannelId ); @Override Object[] getArguments(); @Deprecated void setArguments( Object[] arguments ); boolean isError(); @Override String getCopy(); void setCopy( String copy ); }### Answer: @Test public void testToString() throws Exception { LogMessage msg = new LogMessage( "Log message", "Channel 01", LogLevel.DEBUG ); msg.setSubject( "Simple" ); assertEquals( "Simple - Log message", msg.toString( ) ); }
### Question: MetricsRegistry { public Map<String, Queue<MetricsSnapshotInterface>> getSnapshotLists() { return snapshotLists; } private MetricsRegistry(); static MetricsRegistry getInstance(); void addSnapshot( LogChannelInterface logChannel, MetricsSnapshotInterface snapshot ); Map<String, Queue<MetricsSnapshotInterface>> getSnapshotLists(); Map<String, Map<String, MetricsSnapshotInterface>> getSnapshotMaps(); Queue<MetricsSnapshotInterface> getSnapshotList( String logChannelId ); Map<String, MetricsSnapshotInterface> getSnapshotMap( String logChannelId ); }### Answer: @Test( timeout = 2000 ) public void testConcurrencySnap() throws Exception { ExecutorService service = Executors.newFixedThreadPool( threadCount ); for ( int i = 0; i < threadCount; i++ ) { service.submit( new ConcurrentPutIfAbsent( logIds.get( i % 20 ) ) ); } countDownLatch.countDown(); service.shutdown(); while ( !service.isTerminated() ) { Thread.currentThread().sleep( 1 ); } int expectedQueueCount = logChannelIdCount > threadCount ? threadCount : logChannelIdCount; assertTrue( expectedQueueCount == metricsRegistry.getSnapshotLists().size() ); }
### Question: JndiUtil { public static void initJNDI() throws KettleException { String path = Const.JNDI_DIRECTORY; if ( path == null || path.equals( "" ) ) { try { File file = new File( "simple-jndi" ); path = file.getCanonicalPath(); } catch ( Exception e ) { throw new KettleException( "Error initializing JNDI", e ); } Const.JNDI_DIRECTORY = path; } System.setProperty( "java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory" ); System.setProperty( "org.osjava.sj.root", path ); System.setProperty( "org.osjava.sj.delimiter", "/" ); } static void initJNDI(); }### Answer: @Test public void testInitJNDI() throws Exception { final String factoryInitialKey = "java.naming.factory.initial"; final String factoryInitialBak = System.getProperty( factoryInitialKey ); final String sjRootKey = "org.osjava.sj.root"; final String sjRootBak = System.getProperty( sjRootKey ); final String sjDelimiterKey = "org.osjava.sj.root"; final String sjDelimiterBak = System.getProperty( sjDelimiterKey ); System.clearProperty( factoryInitialKey ); System.clearProperty( sjRootKey ); System.clearProperty( sjDelimiterKey ); JndiUtil.initJNDI(); try { assertFalse( System.getProperty( factoryInitialKey ).isEmpty() ); assertFalse( System.getProperty( sjRootKey ).isEmpty() ); assertFalse( System.getProperty( sjDelimiterKey ).isEmpty() ); assertEquals( System.getProperty( sjRootKey ), Const.JNDI_DIRECTORY ); } finally { if ( factoryInitialBak != null ) { System.setProperty( factoryInitialKey, factoryInitialBak ); } if ( sjRootBak != null ) { System.setProperty( sjRootKey, sjRootBak ); } if ( sjDelimiterBak != null ) { System.setProperty( sjDelimiterKey, sjDelimiterBak ); } } }
### Question: ExtensionPointMap { public void addExtensionPoint( PluginInterface extensionPointPlugin ) { lock.writeLock().lock(); try { for ( String id : extensionPointPlugin.getIds() ) { extensionPointPluginMap.put( extensionPointPlugin.getName(), id, createLazyLoader( extensionPointPlugin ) ); } } finally { lock.writeLock().unlock(); } } private ExtensionPointMap( PluginRegistry pluginRegistry ); static ExtensionPointMap getInstance(); void addExtensionPoint( PluginInterface extensionPointPlugin ); void removeExtensionPoint( PluginInterface extensionPointPlugin ); void reInitialize(); void callExtensionPoint( LogChannelInterface log, String id, Object object ); static LogChannelInterface getLog(); }### Answer: @Test public void addExtensionPointTest() throws KettlePluginException { ExtensionPointMap.getInstance().addExtensionPoint( pluginInterface ); assertEquals( ExtensionPointMap.getInstance().getTableValue( TEST_NAME, "testID" ), extensionPoint ); assertEquals( ExtensionPointMap.getInstance().getTableValue( TEST_NAME, "testID" ), extensionPoint ); verify( pluginInterface, times( 1 ) ).loadClass( any( Class.class ) ); }
### Question: ExtensionPointHandler { public static void callExtensionPoint( final LogChannelInterface log, final String id, final Object object ) throws KettleException { ExtensionPointMap.getInstance().callExtensionPoint( log, id, object ); } static void callExtensionPoint( final LogChannelInterface log, final String id, final Object object ); }### Answer: @Test public void callExtensionPointTest() throws Exception { PluginMockInterface pluginInterface = mock( PluginMockInterface.class ); when( pluginInterface.getName() ).thenReturn( TEST_NAME ); when( pluginInterface.getMainType() ).thenReturn( (Class) ExtensionPointInterface.class ); when( pluginInterface.getIds() ).thenReturn( new String[] {"testID"} ); ExtensionPointInterface extensionPoint = mock( ExtensionPointInterface.class ); when( pluginInterface.loadClass( ExtensionPointInterface.class ) ).thenReturn( extensionPoint ); PluginRegistry.addPluginType( ExtensionPointPluginType.getInstance() ); PluginRegistry.getInstance().registerPlugin( ExtensionPointPluginType.class, pluginInterface ); final LogChannelInterface log = mock( LogChannelInterface.class ); ExtensionPointHandler.callExtensionPoint( log, "noPoint", null ); verify( extensionPoint, never() ).callExtensionPoint( any( LogChannelInterface.class ), any() ); ExtensionPointHandler.callExtensionPoint( log, TEST_NAME, null ); verify( extensionPoint, times( 1 ) ).callExtensionPoint( eq( log ), isNull() ); }
### Question: CertificateGenEncryptUtil { public static Key generateSingleKey() throws NoSuchAlgorithmException { Key key = KeyGenerator.getInstance( SINGLE_KEY_ALGORITHM ).generateKey(); return key; } static KeyPair generateKeyPair(); static Key generateSingleKey(); static byte[] encodeKeyForTransmission( Key encodingKey, Key keyToEncode ); static Key decodeTransmittedKey( byte[] sessionKey, byte[] transmittedKey, boolean privateKey ); static Cipher initDecryptionCipher( Key unwrappedKey, byte[] unencryptedKey ); static byte[] encryptUsingKey( byte[] data, Key key ); static byte[] decryptUsingKey( byte[] data, Key key ); static final int KEY_SIZE; static final String PUBLIC_KEY_ALGORITHM; static final String SINGLE_KEY_ALGORITHM; static final String TRANSMISSION_CIPHER_PARAMS; }### Answer: @Test public void testRandomSessionKeyGeneration() throws Exception { Key key = CertificateGenEncryptUtil.generateSingleKey(); Key key1 = CertificateGenEncryptUtil.generateSingleKey(); assertFalse( key.equals( key1 ) ); assertFalse( Arrays.equals( key.getEncoded(), key1.getEncoded() ) ); }
### Question: QueueRowSet extends BaseRowSet implements Comparable<RowSet>, RowSet { @Override public boolean putRow( RowMetaInterface rowMeta, Object[] rowData ) { this.rowMeta = rowMeta; buffer.add( rowData ); return true; } QueueRowSet(); @Override Object[] getRow(); @Override Object[] getRowImmediate(); @Override Object[] getRowWait( long timeout, TimeUnit tu ); @Override boolean putRow( RowMetaInterface rowMeta, Object[] rowData ); @Override boolean putRowWait( RowMetaInterface rowMeta, Object[] rowData, long time, TimeUnit tu ); @Override int size(); @Override void clear(); }### Answer: @Test public void testPutRow() throws Exception { rowSet.putRow( new RowMeta(), row ); assertSame( row, rowSet.getRow() ); }
### Question: QueueRowSet extends BaseRowSet implements Comparable<RowSet>, RowSet { @Override public boolean putRowWait( RowMetaInterface rowMeta, Object[] rowData, long time, TimeUnit tu ) { return putRow( rowMeta, rowData ); } QueueRowSet(); @Override Object[] getRow(); @Override Object[] getRowImmediate(); @Override Object[] getRowWait( long timeout, TimeUnit tu ); @Override boolean putRow( RowMetaInterface rowMeta, Object[] rowData ); @Override boolean putRowWait( RowMetaInterface rowMeta, Object[] rowData, long time, TimeUnit tu ); @Override int size(); @Override void clear(); }### Answer: @Test public void testPutRowWait() throws Exception { rowSet.putRowWait( new RowMeta(), row, 1, TimeUnit.SECONDS ); assertSame( row, rowSet.getRowWait( 1, TimeUnit.SECONDS ) ); }
### Question: QueueRowSet extends BaseRowSet implements Comparable<RowSet>, RowSet { @Override public Object[] getRowImmediate() { return getRow(); } QueueRowSet(); @Override Object[] getRow(); @Override Object[] getRowImmediate(); @Override Object[] getRowWait( long timeout, TimeUnit tu ); @Override boolean putRow( RowMetaInterface rowMeta, Object[] rowData ); @Override boolean putRowWait( RowMetaInterface rowMeta, Object[] rowData, long time, TimeUnit tu ); @Override int size(); @Override void clear(); }### Answer: @Test public void testGetRowImmediate() throws Exception { rowSet.putRow( new RowMeta(), row ); assertSame( row, rowSet.getRowImmediate() ); }
### Question: QueueRowSet extends BaseRowSet implements Comparable<RowSet>, RowSet { @Override public int size() { return buffer.size(); } QueueRowSet(); @Override Object[] getRow(); @Override Object[] getRowImmediate(); @Override Object[] getRowWait( long timeout, TimeUnit tu ); @Override boolean putRow( RowMetaInterface rowMeta, Object[] rowData ); @Override boolean putRowWait( RowMetaInterface rowMeta, Object[] rowData, long time, TimeUnit tu ); @Override int size(); @Override void clear(); }### Answer: @Test public void testSize() throws Exception { assertEquals( 0, rowSet.size() ); rowSet.putRow( new RowMeta(), row ); assertEquals( 1, rowSet.size() ); rowSet.putRow( new RowMeta(), row ); assertEquals( 2, rowSet.size() ); rowSet.clear(); assertEquals( 0, rowSet.size() ); }
### Question: ValueMetaFactory { public static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ) throws KettlePluginException { return cloneValueMeta( source, source.getType() ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer: @Test public void testClone() throws KettleException { ValueMetaInterface original = new ValueMetaString(); original.setCollatorLocale( Locale.CANADA ); original.setCollatorStrength( 3 ); ValueMetaInterface cloned = ValueMetaFactory.cloneValueMeta( original ); assertNotNull( cloned ); assertNotSame( original, cloned ); valueMetaDeepEquals( original, cloned ); }
### Question: ValueMetaFactory { public static String[] getValueMetaNames() { List<String> strings = new ArrayList<String>(); List<PluginInterface> plugins = pluginRegistry.getPlugins( ValueMetaPluginType.class ); for ( PluginInterface plugin : plugins ) { int id = Integer.valueOf( plugin.getIds()[0] ); if ( id > 0 && id != ValueMetaInterface.TYPE_SERIALIZABLE ) { strings.add( plugin.getName() ); } } return strings.toArray( new String[strings.size()] ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer: @Test public void testGetValueMetaNames() { List<String> dataTypes = Arrays.<String>asList( ValueMetaFactory.getValueMetaNames() ); assertTrue( dataTypes.contains( "Number" ) ); assertTrue( dataTypes.contains( "String" ) ); assertTrue( dataTypes.contains( "Date" ) ); assertTrue( dataTypes.contains( "Boolean" ) ); assertTrue( dataTypes.contains( "Integer" ) ); assertTrue( dataTypes.contains( "BigNumber" ) ); assertFalse( dataTypes.contains( "Serializable" ) ); assertTrue( dataTypes.contains( "Binary" ) ); assertTrue( dataTypes.contains( "Timestamp" ) ); assertTrue( dataTypes.contains( "Internet Address" ) ); }
### Question: ValueMetaFactory { public static String[] getAllValueMetaNames() { List<String> strings = new ArrayList<String>(); List<PluginInterface> plugins = pluginRegistry.getPlugins( ValueMetaPluginType.class ); for ( PluginInterface plugin : plugins ) { String id = plugin.getIds()[0]; if ( !( "0".equals( id ) ) ) { strings.add( plugin.getName() ); } } return strings.toArray( new String[strings.size()] ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer: @Test public void testGetAllValueMetaNames() { List<String> dataTypes = Arrays.<String>asList( ValueMetaFactory.getAllValueMetaNames() ); assertTrue( dataTypes.contains( "Number" ) ); assertTrue( dataTypes.contains( "String" ) ); assertTrue( dataTypes.contains( "Date" ) ); assertTrue( dataTypes.contains( "Boolean" ) ); assertTrue( dataTypes.contains( "Integer" ) ); assertTrue( dataTypes.contains( "BigNumber" ) ); assertTrue( dataTypes.contains( "Serializable" ) ); assertTrue( dataTypes.contains( "Binary" ) ); assertTrue( dataTypes.contains( "Timestamp" ) ); assertTrue( dataTypes.contains( "Internet Address" ) ); }
### Question: WriterOutputStream extends OutputStream { @Override public void write( int b ) throws IOException { write( new byte[] { (byte) b, } ); } WriterOutputStream( Writer writer ); WriterOutputStream( Writer writer, String encoding ); @Override void write( int b ); @Override void write( byte[] b, int off, int len ); @Override void write( byte[] b ); @Override void close(); @Override void flush(); Writer getWriter(); String getEncoding(); }### Answer: @Test public void testWrite() throws IOException { WriterOutputStream stream = new WriterOutputStream( writer ); stream.write( 68 ); stream.write( "value".getBytes(), 1, 3 ); stream.write( "value".getBytes() ); stream.flush(); stream.close(); verify( writer ).append( new String( new byte[] { (byte) 68 } ) ); verify( writer ).append( "alu" ); verify( writer ).append( "value" ); verify( writer ).flush(); verify( writer ).close(); assertNull( stream.getWriter() ); writer = mock( Writer.class ); WriterOutputStream streamWithEncoding = new WriterOutputStream( writer, encoding ); streamWithEncoding.write( "value".getBytes( encoding ) ); verify( writer ).append( "value" ); }
### Question: NamedParamsDefault implements NamedParams { @Override public void addParameterDefinition( String key, String defValue, String description ) throws DuplicateParamException { if ( params.get( key ) == null ) { OneNamedParam oneParam = new OneNamedParam(); oneParam.key = key; oneParam.defaultValue = defValue; oneParam.description = description; oneParam.value = ""; params.put( key, oneParam ); } else { throw new DuplicateParamException( "Duplicate parameter '" + key + "' detected." ); } } NamedParamsDefault(); @Override void addParameterDefinition( String key, String defValue, String description ); @Override String getParameterDescription( String key ); @Override String getParameterValue( String key ); @Override String getParameterDefault( String key ); @Override String[] listParameters(); @Override void setParameterValue( String key, String value ); @Override void eraseParameters(); @Override void clearParameters(); @Override void activateParameters(); @Override void copyParametersFrom( NamedParams aParam ); }### Answer: @Test( expected = DuplicateParamException.class ) public void testAddParameterDefinitionWithException() throws DuplicateParamException { namedParams.addParameterDefinition( "key", "value", "description" ); namedParams.addParameterDefinition( "key", "value", "description" ); }
### Question: NamedParamsDefault implements NamedParams { @Override public void copyParametersFrom( NamedParams aParam ) { if ( params != null && aParam != null ) { params.clear(); String[] keys = aParam.listParameters(); for ( int idx = 0; idx < keys.length; idx++ ) { String desc; try { desc = aParam.getParameterDescription( keys[idx] ); } catch ( UnknownParamException e ) { desc = ""; } String defValue; try { defValue = aParam.getParameterDefault( keys[idx] ); } catch ( UnknownParamException e ) { defValue = ""; } String value; try { value = aParam.getParameterValue( keys[idx] ); } catch ( UnknownParamException e ) { value = ""; } try { addParameterDefinition( keys[idx], defValue, desc ); } catch ( DuplicateParamException e ) { } setParameterValue( keys[idx], value ); } } } NamedParamsDefault(); @Override void addParameterDefinition( String key, String defValue, String description ); @Override String getParameterDescription( String key ); @Override String getParameterValue( String key ); @Override String getParameterDefault( String key ); @Override String[] listParameters(); @Override void setParameterValue( String key, String value ); @Override void eraseParameters(); @Override void clearParameters(); @Override void activateParameters(); @Override void copyParametersFrom( NamedParams aParam ); }### Answer: @Test public void testCopyParametersFromNullChecks() throws Exception { namedParams.copyParametersFrom( null ); NamedParams namedParams2 = new NamedParamsDefault(); ( (NamedParamsDefault) namedParams ).params = null; namedParams.copyParametersFrom( namedParams2 ); } @Test public void testCopyParametersFrom() throws Exception { NamedParams namedParams2 = new NamedParamsDefault(); namedParams2.addParameterDefinition( "key", "default value", "description" ); namedParams2.setParameterValue( "key", "value" ); assertNull( namedParams.getParameterValue( "key" ) ); namedParams.copyParametersFrom( namedParams2 ); assertEquals( "value", namedParams.getParameterValue( "key" ) ); }
### Question: PDIClassLoader extends URLClassLoader { @Override protected synchronized Class<?> loadClass( String name, boolean resolve ) throws ClassNotFoundException { try { return super.loadClass( name, resolve ); } catch ( NoClassDefFoundError e ) { return super.findClass( name ); } } PDIClassLoader( URL[] url, ClassLoader parent ); PDIClassLoader( ClassLoader parent ); }### Answer: @Test public void testLoadClass() throws Exception { final String classToLoad = "dummy.Class"; final AtomicBoolean loadClassCalled = new AtomicBoolean(); ClassLoader parent = new ClassLoader() { @Override protected Class<?> loadClass( String name, boolean resolve ) throws ClassNotFoundException { if ( name.equals( classToLoad ) && !resolve ) { loadClassCalled.set( true ); } throw new NoClassDefFoundError(); } }; PDIClassLoader cl = new PDIClassLoader( parent ); try { cl.loadClass( classToLoad, true ); fail( "This class doesn't exist" ); } catch ( ClassNotFoundException cnfe ) { assertTrue( loadClassCalled.get() ); } }
### Question: LongHashIndex { public Long get( long key ) throws KettleValueException { int hashCode = generateHashCode( key ); int indexPointer = indexFor( hashCode, index.length ); LongHashIndexEntry check = index[indexPointer]; while ( check != null ) { if ( check.hashCode == hashCode && check.equalsKey( key ) ) { return check.value; } check = check.nextEntry; } return null; } LongHashIndex( int size ); LongHashIndex(); int getSize(); boolean isEmpty(); Long get( long key ); void put( long key, Long value ); static int generateHashCode( Long key ); static int indexFor( int hash, int length ); }### Answer: @Test public void testGet() throws KettleValueException { LongHashIndex index = new LongHashIndex(); index.put( 1L, 1L ); assertThat( "Element has uncorrect value.", index.get( 1L ), equalTo( 1L ) ); }
### Question: LongHashIndex { public boolean isEmpty() { return size == 0; } LongHashIndex( int size ); LongHashIndex(); int getSize(); boolean isEmpty(); Long get( long key ); void put( long key, Long value ); static int generateHashCode( Long key ); static int indexFor( int hash, int length ); }### Answer: @Test public void testIsEmpty() throws KettleValueException { LongHashIndex index = new LongHashIndex(); assertThat( "Empty index should return true.", index.isEmpty(), is( true ) ); index.put( 1L, 1L ); assertThat( "Not empty index should return false.", index.isEmpty(), is( false ) ); } @Test public void testIsEmpty() throws HopValueException { LongHashIndex index = new LongHashIndex(); assertThat( "Empty index should return true.", index.isEmpty(), is( true ) ); index.put( 1L, 1L ); assertThat( "Not empty index should return false.", index.isEmpty(), is( false ) ); }
### Question: ByteArrayHashIndex { public int getSize() { return size; } ByteArrayHashIndex( RowMetaInterface keyRowMeta, int size ); ByteArrayHashIndex( RowMetaInterface keyRowMeta ); int getSize(); boolean isEmpty(); byte[] get( byte[] key ); void put( byte[] key, byte[] value ); static int generateHashCode( byte[] key, RowMetaInterface rowMeta ); }### Answer: @Test public void testArraySizeConstructor() { ByteArrayHashIndex obj = new ByteArrayHashIndex( new RowMeta(), 1 ); assertEquals( 1, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 2 ); assertEquals( 2, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 3 ); assertEquals( 4, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 12 ); assertEquals( 16, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 99 ); assertEquals( 128, obj.getSize() ); }
### Question: Variables implements VariableSpace { @Override public String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException { if ( aString == null || aString.length() == 0 ) { return aString; } return StringUtil.substituteField( aString, rowMeta, rowData ); } Variables(); @Override void copyVariablesFrom( VariableSpace space ); @Override VariableSpace getParentVariableSpace(); @Override void setParentVariableSpace( VariableSpace parent ); @Override String getVariable( String variableName, String defaultValue ); @Override String getVariable( String variableName ); @Override boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ); @Override void initializeVariablesFrom( VariableSpace parent ); @Override String[] listVariables(); @Override void setVariable( String variableName, String variableValue ); @Override String environmentSubstitute( String aString ); @Override String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ); @Override String[] environmentSubstitute( String[] string ); @Override void shareVariablesWith( VariableSpace space ); @Override void injectVariables( Map<String, String> prop ); static synchronized VariableSpace getADefaultVariableSpace(); }### Answer: @Test public void testFieldSubstitution() throws KettleValueException { Object[] rowData = new Object[]{ "DataOne", "DataTwo" }; RowMeta rm = new RowMeta(); rm.addValueMeta( new ValueMetaString( "FieldOne" ) ); rm.addValueMeta( new ValueMetaString( "FieldTwo" ) ); Variables vars = new Variables(); assertNull( vars.fieldSubstitute( null, rm, rowData ) ); assertEquals( "", vars.fieldSubstitute( "", rm, rowData ) ); assertEquals( "DataOne", vars.fieldSubstitute( "?{FieldOne}", rm, rowData ) ); assertEquals( "TheDataOne", vars.fieldSubstitute( "The?{FieldOne}", rm, rowData ) ); }
### Question: DataHandler extends AbstractXulEventHandler { public void setDeckChildIndex() { getControls(); int originalSelection = ( dialogDeck == null ? -1 : dialogDeck.getSelectedIndex() ); boolean passed = true; if ( originalSelection == 3 ) { passed = checkPoolingParameters(); } if ( passed ) { int selected = deckOptionsBox.getSelectedIndex(); if ( selected < 0 ) { selected = 0; deckOptionsBox.setSelectedIndex( 0 ); } dialogDeck.setSelectedIndex( selected ); } else { dialogDeck.setSelectedIndex( originalSelection ); deckOptionsBox.setSelectedIndex( originalSelection ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testSetDeckChildIndex() throws Exception { }
### Question: Variables implements VariableSpace { @Override public String environmentSubstitute( String aString ) { if ( aString == null || aString.length() == 0 ) { return aString; } return StringUtil.environmentSubstitute( aString, properties ); } Variables(); @Override void copyVariablesFrom( VariableSpace space ); @Override VariableSpace getParentVariableSpace(); @Override void setParentVariableSpace( VariableSpace parent ); @Override String getVariable( String variableName, String defaultValue ); @Override String getVariable( String variableName ); @Override boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ); @Override void initializeVariablesFrom( VariableSpace parent ); @Override String[] listVariables(); @Override void setVariable( String variableName, String variableValue ); @Override String environmentSubstitute( String aString ); @Override String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ); @Override String[] environmentSubstitute( String[] string ); @Override void shareVariablesWith( VariableSpace space ); @Override void injectVariables( Map<String, String> prop ); static synchronized VariableSpace getADefaultVariableSpace(); }### Answer: @Test public void testEnvironmentSubstitute() { Variables vars = new Variables(); vars.setVariable( "VarOne", "DataOne" ); vars.setVariable( "VarTwo", "DataTwo" ); assertNull( vars.environmentSubstitute( (String) null ) ); assertEquals( "", vars.environmentSubstitute( "" ) ); assertEquals( "DataTwo", vars.environmentSubstitute( "${VarTwo}" ) ); assertEquals( "DataTwoEnd", vars.environmentSubstitute( "${VarTwo}End" ) ); assertEquals( 0, vars.environmentSubstitute( new String[0] ).length ); assertArrayEquals( new String[]{ "DataOne", "TheDataOne" }, vars.environmentSubstitute( new String[]{ "${VarOne}", "The${VarOne}" } ) ); }
### Question: LifecycleException extends Exception { public boolean isSevere() { return severe; } LifecycleException( boolean severe ); LifecycleException( String message, boolean severe ); LifecycleException( Throwable cause, boolean severe ); LifecycleException( String message, Throwable cause, boolean severe ); boolean isSevere(); }### Answer: @Test public void testIsSevere() throws Exception { assertTrue( exception.isSevere() ); } @Test public void testThrowableMessageCtor() { Throwable t = mock( Throwable.class ); exception = new LifecycleException( "message", t, true ); assertEquals( t, exception.getCause() ); assertEquals( "message", exception.getMessage() ); assertTrue( exception.isSevere() ); }
### Question: LifeEventInfo { public State getState() { return state; } void setHint( Hint hint ); String getMessage(); void setMessage( String message ); boolean hasHint( Hint h ); State getState(); void setState( State state ); String getName(); void setName( String name ); }### Answer: @Test public void testGetState() throws Exception { assertNull( info.getState() ); info.setState( LifeEventInfo.State.FAIL ); assertEquals( LifeEventInfo.State.FAIL, info.getState() ); }
### Question: LifeEventInfo { public String getName() { return name; } void setHint( Hint hint ); String getMessage(); void setMessage( String message ); boolean hasHint( Hint h ); State getState(); void setState( State state ); String getName(); void setName( String name ); }### Answer: @Test public void testGetName() throws Exception { assertNull( info.getName() ); info.setName( "name" ); assertEquals( "name", info.getName() ); }
### Question: SlaveConnectionManager { public static SlaveConnectionManager getInstance() { if ( slaveConnectionManager == null ) { slaveConnectionManager = new SlaveConnectionManager(); } return slaveConnectionManager; } private SlaveConnectionManager(); static SlaveConnectionManager getInstance(); HttpClient createHttpClient(); HttpClient createHttpClient( String user, String password ); HttpClient createHttpClient( String user, String password, String proxyHost, int proxyPort, AuthScope authScope ); void shutdown(); }### Answer: @Test public void shouldOverrideDefaultSSLContextByDefault() throws Exception { System.clearProperty( "javax.net.ssl.keyStore" ); SlaveConnectionManager instance = SlaveConnectionManager.getInstance(); assertNotEquals( defaultContext, SSLContext.getDefault() ); } @Test public void shouldNotOverrideDefaultSSLContextIfKeystoreIsSet() throws Exception { System.setProperty( "javax.net.ssl.keyStore", "NONE" ); SlaveConnectionManager instance = SlaveConnectionManager.getInstance(); assertEquals( defaultContext, SSLContext.getDefault() ); }
### Question: HttpUtil { public static String constructUrl( VariableSpace space, String hostname, String port, String webAppName, String serviceAndArguments ) throws UnsupportedEncodingException { return constructUrl( space, hostname, port, webAppName, serviceAndArguments, false ); } static String constructUrl( VariableSpace space, String hostname, String port, String webAppName, String serviceAndArguments ); static String constructUrl( VariableSpace space, String hostname, String port, String webAppName, String serviceAndArguments, boolean isSecure ); static String getPortSpecification( VariableSpace space, String port ); static String decodeBase64ZippedString( String loggingString64 ); static String encodeBase64ZippedString( String in ); static final int ZIP_BUFFER_SIZE; }### Answer: @Test public void testConstructUrl() throws Exception { Variables variables = new Variables(); String expected = "hostname:1234/webAppName?param=value"; Assert.assertEquals( "http: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value" ) ); Assert.assertEquals( "http: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value", false ) ); Assert.assertEquals( "https: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value", true ) ); }
### Question: DataHandler extends AbstractXulEventHandler { public void onPoolingCheck() { if ( poolingCheck != null ) { boolean dis = !poolingCheck.isChecked(); if ( poolSizeBox != null ) { poolSizeBox.setDisabled( dis ); } if ( maxPoolSizeBox != null ) { maxPoolSizeBox.setDisabled( dis ); } if ( poolSizeLabel != null ) { poolSizeLabel.setDisabled( dis ); } if ( maxPoolSizeLabel != null ) { maxPoolSizeLabel.setDisabled( dis ); } if ( poolParameterTree != null ) { poolParameterTree.setDisabled( dis ); } if ( poolingParameterDescriptionLabel != null ) { poolingParameterDescriptionLabel.setDisabled( dis ); } if ( poolingDescriptionLabel != null ) { poolingDescriptionLabel.setDisabled( dis ); } if ( poolingDescription != null ) { poolingDescription.setDisabled( dis ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testOnPoolingCheck() throws Exception { }
### Question: Rest extends BaseStep implements StepInterface { MultivaluedMapImpl createMultivalueMap( String paramName, String paramValue ) { MultivaluedMapImpl queryParams = new MultivaluedMapImpl(); queryParams.add( paramName, UriComponent.encode( paramValue, UriComponent.Type.QUERY_PARAM ) ); return queryParams; } Rest( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void testCreateMultivalueMap() { StepMeta stepMeta = new StepMeta(); stepMeta.setName( "TestRest" ); TransMeta transMeta = new TransMeta(); transMeta.setName( "TestRest" ); transMeta.addStep( stepMeta ); Rest rest = new Rest( stepMeta, Mockito.mock( StepDataInterface.class ), 1, transMeta, Mockito.mock( Trans.class ) ); MultivaluedMapImpl map = rest.createMultivalueMap( "param1", "{a:{[val1]}}" ); String val1 = map.getFirst( "param1" ); Assert.assertTrue( val1.contains( "%7D" ) ); }
### Question: JoinRows extends BaseStep implements StepInterface { public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { meta = (JoinRowsMeta) smi; data = (JoinRowsData) sdi; if ( data.file != null ) { for ( int i = 1; i < data.file.length; i++ ) { if ( data.file[i] != null ) { data.file[i].delete(); } } } super.dispose( meta, data ); } JoinRows( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); @SuppressWarnings( "unchecked" ) void initialize(); Object[] getRowData( int filenr ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); @Override void batchComplete(); }### Answer: @Test public void checkThatMethodPerformedWithoutError() throws Exception { getJoinRows().dispose( meta, data ); } @Test public void disposeDataFiles() throws Exception { File mockFile1 = mock( File.class ); File mockFile2 = mock( File.class ); data.file = new File[] {null, mockFile1, mockFile2}; getJoinRows().dispose( meta, data ); verify( mockFile1, times( 1 ) ).delete(); verify( mockFile2, times( 1 ) ).delete(); }
### Question: DataHandler extends AbstractXulEventHandler { public void onClusterCheck() { if ( clusteringCheck != null ) { boolean dis = !clusteringCheck.isChecked(); if ( clusterParameterTree != null ) { clusterParameterTree.setDisabled( dis ); } if ( clusterParameterDescriptionLabel != null ) { clusterParameterDescriptionLabel.setDisabled( dis ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testOnClusterCheck() throws Exception { }
### Question: DataHandler extends AbstractXulEventHandler { public void onCancel() { close(); } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testOnCancel() throws Exception { }
### Question: SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkRemoteFilenameField( String remoteFilenameFieldName, SFTPPutData data ) throws KettleStepException { remoteFilenameFieldName = environmentSubstitute( remoteFilenameFieldName ); if ( !Utils.isEmpty( remoteFilenameFieldName ) ) { data.indexOfRemoteFilename = getInputRowMeta().indexOfValue( remoteFilenameFieldName ); if ( data.indexOfRemoteFilename == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", remoteFilenameFieldName ) ); } } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void checkRemoteFilenameField_FieldNameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkRemoteFilenameField( "", data ); assertEquals( -1, data.indexOfSourceFileFieldName ); } @Test( expected = KettleStepException.class ) public void checkRemoteFilenameField_FieldNameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkRemoteFilenameField( "remoteFileName", new SFTPPutData() ); } @Test public void checkRemoteFilenameField_FieldNameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "remoteFileName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkRemoteFilenameField( "remoteFileName", data ); assertEquals( 1, data.indexOfRemoteFilename ); }
### Question: SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkSourceFileField( String sourceFilenameFieldName, SFTPPutData data ) throws KettleStepException { sourceFilenameFieldName = environmentSubstitute( sourceFilenameFieldName ); if ( Utils.isEmpty( sourceFilenameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.SourceFileNameFieldMissing" ) ); } data.indexOfSourceFileFieldName = getInputRowMeta().indexOfValue( sourceFilenameFieldName ); if ( data.indexOfSourceFileFieldName == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", sourceFilenameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test( expected = KettleStepException.class ) public void checkSourceFileField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkSourceFileField( "", data ); } @Test( expected = KettleStepException.class ) public void checkSourceFileField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkSourceFileField( "sourceFile", new SFTPPutData() ); } @Test public void checkSourceFileField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "sourceFileFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkSourceFileField( "sourceFileFieldName", data ); assertEquals( 1, data.indexOfSourceFileFieldName ); }
### Question: SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkRemoteFoldernameField( String remoteFoldernameFieldName, SFTPPutData data ) throws KettleStepException { remoteFoldernameFieldName = environmentSubstitute( remoteFoldernameFieldName ); if ( Utils.isEmpty( remoteFoldernameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.RemoteFolderNameFieldMissing" ) ); } data.indexOfRemoteDirectory = getInputRowMeta().indexOfValue( remoteFoldernameFieldName ); if ( data.indexOfRemoteDirectory == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", remoteFoldernameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test( expected = KettleStepException.class ) public void checkRemoteFoldernameField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkRemoteFoldernameField( "", data ); } @Test( expected = KettleStepException.class ) public void checkRemoteFoldernameField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkRemoteFoldernameField( "remoteFolder", new SFTPPutData() ); } @Test public void checkRemoteFoldernameField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "remoteFoldernameFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkRemoteFoldernameField( "remoteFoldernameFieldName", data ); assertEquals( 1, data.indexOfRemoteDirectory ); }
### Question: DataHandler extends AbstractXulEventHandler { public void onOK() { DatabaseMeta database = new DatabaseMeta(); this.getInfo( database ); boolean passed = checkPoolingParameters(); if ( !passed ) { return; } String[] remarks = database.checkParameters(); String message = ""; if ( remarks.length != 0 ) { for ( int i = 0; i < remarks.length; i++ ) { message = message.concat( "* " ).concat( remarks[i] ).concat( System.getProperty( "line.separator" ) ); } showMessage( message, false ); } else { if ( databaseMeta == null ) { databaseMeta = new DatabaseMeta(); } this.getInfo( databaseMeta ); databaseMeta.setChanged(); close(); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testOnOK() throws Exception { }
### Question: SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkDestinationFolderField( String realDestinationFoldernameFieldName, SFTPPutData data ) throws KettleStepException { realDestinationFoldernameFieldName = environmentSubstitute( realDestinationFoldernameFieldName ); if ( Utils.isEmpty( realDestinationFoldernameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Log.DestinatFolderNameFieldNameMissing" ) ); } data.indexOfMoveToFolderFieldName = getInputRowMeta().indexOfValue( realDestinationFoldernameFieldName ); if ( data.indexOfMoveToFolderFieldName == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", realDestinationFoldernameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test( expected = KettleStepException.class ) public void checkDestinationFolderField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkDestinationFolderField( "", data ); } @Test( expected = KettleStepException.class ) public void checkDestinationFolderField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkDestinationFolderField( "destinationFolder", new SFTPPutData() ); } @Test public void checkDestinationFolderField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "destinationFolderFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkDestinationFolderField( "destinationFolderFieldName", data ); assertEquals( 1, data.indexOfMoveToFolderFieldName ); }
### Question: SystemDataMeta extends BaseStepMeta implements StepMetaInterface { @Override public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException { readData( stepnode ); } SystemDataMeta(); String[] getFieldName(); void setFieldName( String[] fieldName ); SystemDataTypes[] getFieldType(); void setFieldType( SystemDataTypes[] fieldType ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int count ); @Override Object clone(); static final SystemDataTypes getType( String type ); static final String getTypeDesc( SystemDataTypes t ); @Override void setDefault(); @Override void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); @Override Map<String, String> getUsedArguments(); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); @Override StepDataInterface getStepData(); @Override boolean equals( Object o ); @Override int hashCode(); }### Answer: @Test public void testLoadXML() throws Exception { SystemDataMeta systemDataMeta = new SystemDataMeta(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse( new InputSource( new StringReader( expectedXML ) ) ); Node node = document; IMetaStore store = null; systemDataMeta.loadXML( node, null, store ); assertEquals( expectedSystemDataMeta, systemDataMeta ); }
### Question: MissingTransStep extends DummyTrans { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { if ( super.init( smi, sdi ) ) { logError( BaseMessages.getString( PKG, "MissingTransStep.Log.CannotRunTrans" ) ); } return false; } MissingTransStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void testInit() { StepMetaInterface stepMetaInterface = new AbstractStepMeta() { @Override public void setDefault() { } @Override public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ) { return null; } }; StepMeta stepMeta = new StepMeta(); stepMeta.setName( "TestMetaStep" ); StepDataInterface stepDataInterface = mock( StepDataInterface.class ); Trans trans = new Trans(); LogChannel log = mock( LogChannel.class ); doAnswer( new Answer<Void>() { public Void answer( InvocationOnMock invocation ) { return null; } } ).when( log ).logError( anyString() ); trans.setLog( log ); TransMeta transMeta = new TransMeta(); transMeta.addStep( stepMeta ); MissingTransStep step = createAndInitStep( stepMetaInterface, stepDataInterface ); assertFalse( step.init( stepMetaInterface, stepDataInterface ) ); }
### Question: DataHandler extends AbstractXulEventHandler { public void restoreDefaults() { if ( poolParameterTree != null ) { for ( int i = 0; i < poolParameterTree.getRootChildren().getItemCount(); i++ ) { XulTreeItem item = poolParameterTree.getRootChildren().getItem( i ); String parameterName = item.getRow().getCell( 1 ).getLabel(); String defaultValue = DatabaseConnectionPoolParameter .findParameter( parameterName, BaseDatabaseMeta.poolingParameters ).getDefaultValue(); if ( ( defaultValue == null ) || ( defaultValue.trim().length() <= 0 ) ) { continue; } item.getRow().addCellText( 2, defaultValue ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testRestoreDefaults() throws Exception { }
### Question: CalculatorData extends BaseStepData implements StepDataInterface { public ValueMetaInterface getValueMetaFor( int resultType, String name ) throws KettlePluginException { ValueMetaInterface meta = resultMetaMapping.get( resultType ); if ( meta == null ) { meta = ValueMetaFactory.createValueMeta( name, resultType ); resultMetaMapping.put( resultType, meta ); } return meta; } CalculatorData(); RowMetaInterface getOutputRowMeta(); void setOutputRowMeta( RowMetaInterface outputRowMeta ); RowMetaInterface getCalcRowMeta(); void setCalcRowMeta( RowMetaInterface calcRowMeta ); Calculator.FieldIndexes[] getFieldIndexes(); void setFieldIndexes( Calculator.FieldIndexes[] fieldIndexes ); int[] getTempIndexes(); void setTempIndexes( int[] tempIndexes ); ValueMetaInterface getValueMetaFor( int resultType, String name ); void clearValuesMetaMapping(); }### Answer: @Test public void dataReturnsCachedValues() throws Exception { KettleEnvironment.init( false ); CalculatorData data = new CalculatorData(); ValueMetaInterface valueMeta = data.getValueMetaFor( ValueMetaInterface.TYPE_INTEGER, null ); ValueMetaInterface shouldBeTheSame = data.getValueMetaFor( ValueMetaInterface.TYPE_INTEGER, null ); assertTrue( "CalculatorData should cache loaded value meta instances", valueMeta == shouldBeTheSame ); }
### Question: CalculatorMeta extends BaseStepMeta implements StepMetaInterface { @Override public StepDataInterface getStepData() { return new CalculatorData(); } CalculatorMetaFunction[] getCalculation(); void setCalculation( CalculatorMetaFunction[] calcTypes ); void allocate( int nrCalcs ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); @Override String getXML(); @Override boolean equals( Object obj ); @Override int hashCode(); @Override Object clone(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); RowMetaInterface getAllFields( RowMetaInterface inputRowMeta ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr, Trans trans ); @Override StepDataInterface getStepData(); }### Answer: @Test public void testGetStepData() { CalculatorMeta meta = new CalculatorMeta(); assertTrue( meta.getStepData() instanceof CalculatorData ); }
### Question: CalculatorMeta extends BaseStepMeta implements StepMetaInterface { @Override public void setDefault() { calculation = new CalculatorMetaFunction[0]; } CalculatorMetaFunction[] getCalculation(); void setCalculation( CalculatorMetaFunction[] calcTypes ); void allocate( int nrCalcs ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); @Override String getXML(); @Override boolean equals( Object obj ); @Override int hashCode(); @Override Object clone(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); RowMetaInterface getAllFields( RowMetaInterface inputRowMeta ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr, Trans trans ); @Override StepDataInterface getStepData(); }### Answer: @Test public void testSetDefault() { CalculatorMeta meta = new CalculatorMeta(); meta.setDefault(); assertNotNull( meta.getCalculation() ); assertEquals( 0, meta.getCalculation().length ); }
### Question: StepDefinition implements Cloneable { public Object clone() throws CloneNotSupportedException { StepDefinition retval; retval = (StepDefinition) super.clone(); if ( stepMeta != null ) { retval.stepMeta = (StepMeta) stepMeta.clone(); } return retval; } StepDefinition(); StepDefinition( String tag, String stepName, StepMeta stepMeta, String description ); Object clone(); public String tag; public String stepName; public StepMeta stepMeta; public String description; }### Answer: @Test public void testClone() throws Exception { try { StepDefinition stepDefinition = new StepDefinition( "tag", "stepName", null, "" ); stepDefinition.clone(); } catch ( NullPointerException npe ) { fail( "Null value is not handled" ); } }
### Question: DataHandler extends AbstractXulEventHandler { public void poolingRowChange( int idx ) { if ( idx != -1 ) { if ( idx >= BaseDatabaseMeta.poolingParameters.length ) { idx = BaseDatabaseMeta.poolingParameters.length - 1; } if ( idx < 0 ) { idx = 0; } poolingDescription.setValue( BaseDatabaseMeta.poolingParameters[idx].getDescription() ); XulTreeRow row = poolParameterTree.getRootChildren().getItem( idx ).getRow(); if ( row.getSelectedColumnIndex() == 2 ) { row.addCellText( 0, "true" ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testPoolingRowChange() throws Exception { }
### Question: Script extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (ScriptMeta) smi; data = (ScriptData) sdi; if ( super.init( smi, sdi ) ) { jsScripts = meta.getJSScripts(); for ( int j = 0; j < jsScripts.length; j++ ) { switch ( jsScripts[ j ].getScriptType() ) { case ScriptValuesScript.TRANSFORM_SCRIPT: strTransformScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.START_SCRIPT: strStartScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.END_SCRIPT: strEndScript = jsScripts[ j ].getScript(); break; default: break; } } return true; } return false; } Script( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); Object getValueFromJScript( Object result, int i ); RowMetaInterface getOutputRowMeta(); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final int SKIP_TRANSFORMATION; static final int ABORT_TRANSFORMATION; static final int ERROR_TRANSFORMATION; static final int CONTINUE_TRANSFORMATION; }### Answer: @Test public void testOutputDoneIfInputEmpty() throws Exception { Script step = new Script( helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans ); step.init( helper.initStepMetaInterface, helper.initStepDataInterface ); RowSet rs = helper.getMockInputRowSet( new Object[ 0 ][ 0 ] ); List<RowSet> in = new ArrayList<RowSet>(); in.add( rs ); step.setInputRowSets( in ); TransTestingUtil.execute( step, helper.processRowsStepMetaInterface, helper.processRowsStepDataInterface, 0, true ); rs.getRow(); }
### Question: DatabaseConnectionDialog { public XulDomContainer getSwtInstance( Shell shell ) throws XulException { SwtXulLoader loader = new SwtXulLoader(); return getSwtInstance( loader, shell ); } DatabaseConnectionDialog(); void registerClass( String key, String className ); XulDomContainer getSwtInstance( Shell shell ); XulDomContainer getSwtInstance( SwtXulLoader loader, Shell shell ); static final String DIALOG_DEFINITION_FILE; }### Answer: @Test public void testGetSwtInstance() throws Exception { }
### Question: TableOutput extends BaseStep implements StepInterface { void truncateTable() throws KettleDatabaseException { if ( !meta.isPartitioningEnabled() && !meta.isTableNameInField() ) { if ( meta.truncateTable() && ( ( getCopy() == 0 && getUniqueStepNrAcrossSlaves() == 0 ) || !Utils.isEmpty( getPartitionID() ) ) ) { data.db.truncateTable( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta .getTableName() ) ); } } } TableOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean isRowLevel(); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void testTruncateTable_off() throws Exception { tableOutputSpy.truncateTable(); verify( db, never() ).truncateTable( anyString(), anyString() ); } @Test public void testTruncateTable_on() throws Exception { when( tableOutputMeta.truncateTable() ).thenReturn( true ); when( tableOutputSpy.getCopy() ).thenReturn( 0 ); when( tableOutputSpy.getUniqueStepNrAcrossSlaves() ).thenReturn( 0 ); tableOutputSpy.truncateTable(); verify( db ).truncateTable( anyString(), anyString() ); } @Test public void testTruncateTable_on_PartitionId() throws Exception { when( tableOutputMeta.truncateTable() ).thenReturn( true ); when( tableOutputSpy.getCopy() ).thenReturn( 1 ); when( tableOutputSpy.getUniqueStepNrAcrossSlaves() ).thenReturn( 0 ); when( tableOutputSpy.getPartitionID() ).thenReturn( "partition id" ); tableOutputSpy.truncateTable(); verify( db ).truncateTable( anyString(), anyString() ); }
### Question: SplitFieldToRows extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SplitFieldToRowsMeta) smi; data = (SplitFieldToRowsData) sdi; if ( super.init( smi, sdi ) ) { data.rownr = 1L; try { String delimiter = Const.nullToEmpty( meta.getDelimiter() ); if ( meta.isDelimiterRegex() ) { data.delimiterPattern = Pattern.compile( environmentSubstitute( delimiter ) ); } else { data.delimiterPattern = Pattern.compile( Pattern.quote( environmentSubstitute( delimiter ) ) ); } } catch ( PatternSyntaxException pse ) { log.logError( pse.getMessage() ); throw pse; } return true; } return false; } SplitFieldToRows( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void interpretsNullDelimiterAsEmpty() throws Exception { SplitFieldToRows step = StepMockUtil.getStep( SplitFieldToRows.class, SplitFieldToRowsMeta.class, "handlesNullDelimiter" ); SplitFieldToRowsMeta meta = new SplitFieldToRowsMeta(); meta.setDelimiter( null ); meta.setDelimiterRegex( false ); SplitFieldToRowsData data = new SplitFieldToRowsData(); step.init( meta, data ); assertEquals( "\\Q\\E", data.delimiterPattern.pattern() ); }
### Question: DataHandler extends AbstractXulEventHandler { public void disablePortIfInstancePopulated() { String serverInstance = serverInstanceBox.getValue(); if ( serverInstance != null && serverInstance.length() > 0 ) { portNumberBox.setDisabled( true ); } else { portNumberBox.setDisabled( false ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testDisablePortIfInstancePopulated() throws Exception { dataHandler.getControls(); dataHandler.disablePortIfInstancePopulated(); when( serverInstanceBox.getValue() ).thenReturn( null ); dataHandler.disablePortIfInstancePopulated(); assertFalse( dataHandler.portNumberBox.isDisabled() ); }
### Question: DataHandler extends AbstractXulEventHandler { protected void showMessage( String message, boolean scroll ) { try { XulMessageBox box = (XulMessageBox) document.createElement( "messagebox" ); box.setMessage( message ); box.setModalParent( ( (XulRoot) document.getElementById( "general-datasource-window" ) ).getRootObject() ); if ( scroll ) { box.setScrollable( true ); box.setWidth( 500 ); box.setHeight( 400 ); } box.open(); } catch ( XulException e ) { System.out.println( "Error creating messagebox " + e.getMessage() ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testShowMessage() throws Exception { dataHandler.showMessage( "MyMessage", false ); dataHandler.showMessage( "MyMessage", true ); when( document.createElement( "messagebox" ) ).thenThrow( new XulException() ); dataHandler.showMessage( "MyMessage", false ); }
### Question: ExcelWriterStep extends BaseStep implements StepInterface { protected void protectSheet( Sheet sheet, String password ) { if ( sheet instanceof HSSFSheet ) { sheet.protectSheet( password ); } } ExcelWriterStep( StepMeta s, StepDataInterface stepDataInterface, int c, TransMeta t, Trans dis ); @Override boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void writeNextLine( Object[] r ); String buildFilename( int splitNr ); static void copyFile( FileObject in, FileObject out ); void prepareNextOutputFile(); @Override boolean init( StepMetaInterface smi, StepDataInterface sdi ); @Override void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final String STREAMER_FORCE_RECALC_PROP_NAME; }### Answer: @Test public void testProtectSheet() throws Exception { step.protectSheet( wb.getSheet( SHEET_NAME ), "aa" ); assertTrue( wb.getSheet( SHEET_NAME ).getProtect() ); }
### Question: LdapProtocolFactory { public LdapProtocol createLdapProtocol( VariableSpace variableSpace, LdapMeta meta, Collection<String> binaryAttributes ) throws KettleException { String connectionType = variableSpace.environmentSubstitute( meta.getProtocol() ); synchronized ( protocols ) { for ( Class<? extends LdapProtocol> protocol : protocols ) { if ( getName( protocol ).equals( connectionType ) ) { try { return protocol.getConstructor( LogChannelInterface.class, VariableSpace.class, LdapMeta.class, Collection.class ).newInstance( log, variableSpace, meta, binaryAttributes ); } catch ( Exception e ) { throw new KettleException( e ); } } } } return null; } LdapProtocolFactory( LogChannelInterface log ); static final List<String> getConnectionTypes( LogChannelInterface log ); LdapProtocol createLdapProtocol( VariableSpace variableSpace, LdapMeta meta, Collection<String> binaryAttributes ); }### Answer: @Test public void createLdapProtocol() throws Exception { String ldapVariable = "${ldap_protocol_variable}"; String ldap = "LDAP"; String host = "localhost"; LdapProtocolFactory ldapProtocolFactory = new LdapProtocolFactory( Mockito.mock( LogChannelInterface.class ) ); VariableSpace variableSpace = Mockito.mock( VariableSpace.class ); LdapMeta meta = Mockito.mock( LdapMeta.class ); Mockito.doReturn( ldapVariable ).when( meta ).getProtocol(); Mockito.doReturn( ldap ).when( variableSpace ).environmentSubstitute( ldapVariable ); Mockito.doReturn( host ).when( meta ).getHost(); Mockito.doReturn( host ).when( variableSpace ).environmentSubstitute( host ); ldapProtocolFactory.createLdapProtocol( variableSpace, meta, Collections.emptyList() ); Mockito.verify( variableSpace, Mockito.times( 1 ) ).environmentSubstitute( ldapVariable ); }
### Question: NamedFieldsMapping implements FieldsMapping { @Override public int fieldMetaIndex( int index ) { if ( index >= size() || index < 0 ) { return FIELD_DOES_NOT_EXIST; } return actualToMetaFieldMapping[index]; } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer: @Test public void fieldMetaIndex() { assertEquals( 3, fieldsMapping.fieldMetaIndex( 0 ) ); } @Test public void fieldMetaIndexWithUnexistingField() { assertEquals( FieldsMapping.FIELD_DOES_NOT_EXIST, fieldsMapping.fieldMetaIndex( 4 ) ); }
### Question: DataHandler extends AbstractXulEventHandler { public void handleUseSecurityCheckbox() { if ( useIntegratedSecurityCheck != null ) { if ( useIntegratedSecurityCheck.isChecked() ) { userNameBox.setDisabled( true ); passwordBox.setDisabled( true ); } else { userNameBox.setDisabled( false ); passwordBox.setDisabled( false ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer: @Test public void testHandleUseSecurityCheckbox() throws Exception { dataHandler.handleUseSecurityCheckbox(); XulCheckbox useIntegratedSecurityCheck = mock( XulCheckbox.class ); when( useIntegratedSecurityCheck.isChecked() ).thenReturn( false ); when( document.getElementById( "use-integrated-security-check" ) ).thenReturn( useIntegratedSecurityCheck ); dataHandler.getControls(); dataHandler.handleUseSecurityCheckbox(); when( useIntegratedSecurityCheck.isChecked() ).thenReturn( true ); dataHandler.handleUseSecurityCheckbox(); }
### Question: NamedFieldsMapping implements FieldsMapping { @Override public int size() { return actualToMetaFieldMapping.length; } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer: @Test public void size() { assertEquals( 2, fieldsMapping.size() ); }
### Question: NamedFieldsMapping implements FieldsMapping { public static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ) { LinkedHashMap<String, List<Integer>> metaNameToIndex = new LinkedHashMap<>(); List<Integer> unmatchedMetaFields = new ArrayList<>(); int[] actualToMetaFieldMapping = new int[actualFieldNames.length]; for ( int i = 0; i < metaFieldNames.length; i++ ) { List<Integer> coll = metaNameToIndex.getOrDefault( metaFieldNames[i], new ArrayList<>() ); coll.add( i ); metaNameToIndex.put( metaFieldNames[i], coll ); } for ( int i = 0; i < actualFieldNames.length; i++ ) { List<Integer> columnIndexes = metaNameToIndex.get( actualFieldNames[i] ); if ( columnIndexes == null || columnIndexes.isEmpty() ) { unmatchedMetaFields.add( i ); actualToMetaFieldMapping[i] = FIELD_DOES_NOT_EXIST; continue; } actualToMetaFieldMapping[i] = columnIndexes.remove( 0 ); } Iterator<Integer> remainingMetaIndexes = metaNameToIndex.values().stream() .flatMap( List::stream ) .sorted() .iterator(); for ( int idx : unmatchedMetaFields ) { if ( !remainingMetaIndexes.hasNext() ) { break; } actualToMetaFieldMapping[ idx ] = remainingMetaIndexes.next(); } return new NamedFieldsMapping( actualToMetaFieldMapping ); } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer: @Test public void mapping() { NamedFieldsMapping mapping = NamedFieldsMapping.mapping( new String[] { "FIRST", "SECOND", "THIRD" }, new String[] { "SECOND", "THIRD" } ); assertEquals( 0, mapping.fieldMetaIndex( 1 ) ); }
### Question: UnnamedFieldsMapping implements FieldsMapping { @Override public int fieldMetaIndex( int index ) { return ( index >= fieldsCount || index < 0 ) ? FieldsMapping.FIELD_DOES_NOT_EXIST : index; } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer: @Test public void fieldMetaIndex() { assertEquals( 1, fieldsMapping.fieldMetaIndex( 1 ) ); } @Test public void fieldMetaIndexWithUnexistingField() { assertEquals( FieldsMapping.FIELD_DOES_NOT_EXIST, fieldsMapping.fieldMetaIndex( 2 ) ); }
### Question: UnnamedFieldsMapping implements FieldsMapping { @Override public int size() { return fieldsCount; } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer: @Test public void size() { assertEquals( 2, fieldsMapping.size() ); }
### Question: UnnamedFieldsMapping implements FieldsMapping { public static UnnamedFieldsMapping mapping( int fieldsCount ) { return new UnnamedFieldsMapping( fieldsCount ); } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer: @Test public void mapping() { UnnamedFieldsMapping mapping = UnnamedFieldsMapping.mapping( 2 ); assertEquals( 1, mapping.fieldMetaIndex( 1 ) ); }
### Question: CreditCardVerifier { public static boolean isNumber( String n ) { try { Double.valueOf( n ).doubleValue(); return true; } catch ( NumberFormatException e ) { return false; } } static String getCardName( int id ); static String getNotValidCardNames( int id ); static ReturnIndicator CheckCC( String CardNumber ); static boolean luhnValidate( String numberString ); static int getCardID( String number ); static boolean isNumber( String n ); static final int INVALID; static final int VISA; static final int MASTERCARD; static final int AMERICAN_EXPRESS; static final int EN_ROUTE; static final int DINERS_CLUB; static final int DISCOVER; static final int JCB1; static final int JCB2; static final int BANKCARD; static final int MAESTRO; static final int SOLO; static final int SWITCH; static final int AIRPLUS; static final int LASER; static final int VOYAGER; }### Answer: @Test public void testIsNumber() { assertFalse( CreditCardVerifier.isNumber( "" ) ); assertFalse( CreditCardVerifier.isNumber( "a" ) ); assertTrue( CreditCardVerifier.isNumber( "1" ) ); assertTrue( CreditCardVerifier.isNumber( "1.01" ) ); }
### Question: CreditCardValidatorMeta extends BaseStepMeta implements StepMetaInterface { public boolean supportsErrorHandling() { return true; } CreditCardValidatorMeta(); String getDynamicField(); void setDynamicField( String fieldname ); String getResultFieldName(); void setOnlyDigits( boolean onlydigits ); boolean isOnlyDigits(); void setResultFieldName( String resultfieldname ); void setCardType( String cardtype ); String getCardType(); void setNotValidMsg( String notvalidmsg ); String getNotValidMsg(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); }### Answer: @Test public void testSupportsErrorHandling() { assertTrue( new CreditCardValidatorMeta().supportsErrorHandling() ); }
### Question: TransExecutorParameters implements Cloneable { @Override public Object clone() { try { TransExecutorParameters retval = (TransExecutorParameters) super.clone(); int nrVariables = variable.length; retval.allocate( nrVariables ); System.arraycopy( variable, 0, retval.variable, 0, nrVariables ); System.arraycopy( field, 0, retval.field, 0, nrVariables ); System.arraycopy( input, 0, retval.input, 0, nrVariables ); return retval; } catch ( CloneNotSupportedException e ) { throw new RuntimeException( e ); } } TransExecutorParameters(); TransExecutorParameters( Node paramNode ); TransExecutorParameters( Repository rep, ObjectId id_step ); void allocate( int nrVariables ); @Override Object clone(); String getXML(); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); String[] getField(); void setField( String[] field ); String[] getVariable(); void setVariable( String[] variable ); boolean isInheritingAllVariables(); void setInheritingAllVariables( boolean inheritingAllVariables ); String[] getInput(); void setInput( String[] input ); static final String XML_TAG; }### Answer: @Test public void testClone() throws Exception { TransExecutorParameters meta = new TransExecutorParameters(); meta.setField( new String[] { "field1", "field2" } ); meta.setVariable( new String[] { "var1", "var2" } ); meta.setInput( new String[] { "input1", "input2" } ); TransExecutorParameters cloned = (TransExecutorParameters) meta.clone(); assertFalse( cloned.getField() == meta.getField() ); assertTrue( Arrays.equals( cloned.getField(), meta.getField() ) ); assertFalse( cloned.getVariable() == meta.getVariable() ); assertTrue( Arrays.equals( cloned.getVariable(), meta.getVariable() ) ); assertFalse( cloned.getInput() == meta.getInput() ); assertTrue( Arrays.equals( cloned.getInput(), meta.getInput() ) ); }
### Question: FragmentHandler extends AbstractXulEventHandler { protected void loadDatabaseOptionsFragment( String fragmentUri ) throws XulException { XulComponent groupElement = document.getElementById( "database-options-box" ); XulComponent parentElement = groupElement.getParent(); XulDomContainer fragmentContainer; try { fragmentContainer = this.xulDomContainer.loadFragment( fragmentUri, Messages.getBundle() ); XulComponent newGroup = fragmentContainer.getDocumentRoot().getFirstChild(); parentElement.replaceChild( groupElement, newGroup ); } catch ( XulException e ) { e.printStackTrace(); throw e; } } FragmentHandler(); void refreshOptions(); Object getData(); void setData( Object arg0 ); }### Answer: @Test public void testLoadDatabaseOptionsFragment() throws Exception { XulComponent component = mock( XulComponent.class ); XulComponent parent = mock( XulComponent.class ); when( component.getParent() ).thenReturn( parent ); when( document.getElementById( "database-options-box" ) ).thenReturn( component ); XulDomContainer fragmentContainer = mock( XulDomContainer.class ); Document mockDoc = mock( Document.class ); XulComponent firstChild = mock( XulComponent.class ); when( mockDoc.getFirstChild() ).thenReturn( firstChild ); when( fragmentContainer.getDocumentRoot() ).thenReturn( mockDoc ); when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenReturn( fragmentContainer ); fragmentHandler.loadDatabaseOptionsFragment( null ); } @Test( expected = XulException.class ) public void testLoadDatabaseOptionsFragmentWithException() throws Exception { XulComponent component = mock( XulComponent.class ); XulComponent parent = mock( XulComponent.class ); when( component.getParent() ).thenReturn( parent ); when( document.getElementById( "database-options-box" ) ).thenReturn( component ); when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenThrow( new XulException() ); fragmentHandler.loadDatabaseOptionsFragment( null ); }
### Question: DetectLastRowMeta extends BaseStepMeta implements StepMetaInterface { public StepDataInterface getStepData() { return new DetectLastRowData(); } String getResultFieldName(); void setResultFieldName( String resultfieldname ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); TransformationType[] getSupportedTransformationTypes(); }### Answer: @Test public void testGetData() { DetectLastRowMeta meta = new DetectLastRowMeta(); assertTrue( meta.getStepData() instanceof DetectLastRowData ); }
### Question: DetectLastRowMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { if ( !Utils.isEmpty( resultfieldname ) ) { ValueMetaInterface v = new ValueMetaBoolean( space.environmentSubstitute( resultfieldname ) ); v.setOrigin( name ); row.addValueMeta( v ); } } String getResultFieldName(); void setResultFieldName( String resultfieldname ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); TransformationType[] getSupportedTransformationTypes(); }### Answer: @Test public void testGetFields() throws KettleStepException { DetectLastRowMeta meta = new DetectLastRowMeta(); meta.setDefault(); meta.setResultFieldName( "The Result" ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null ); assertEquals( 1, rowMeta.size() ); assertEquals( "The Result", rowMeta.getValueMeta( 0 ).getName() ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() ); }
### Question: DetectLastRowMeta extends BaseStepMeta implements StepMetaInterface { public TransformationType[] getSupportedTransformationTypes() { return new TransformationType[] { TransformationType.Normal, }; } String getResultFieldName(); void setResultFieldName( String resultfieldname ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); TransformationType[] getSupportedTransformationTypes(); }### Answer: @Test public void testSupportedTransformationTypes() { DetectLastRowMeta meta = new DetectLastRowMeta(); assertEquals( 1, meta.getSupportedTransformationTypes().length ); assertEquals( TransformationType.Normal, meta.getSupportedTransformationTypes()[0] ); }
### Question: WebService extends BaseStep implements StepInterface { HttpPost getHttpMethod( String vURLService ) throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder( vURLService ); HttpPost vHttpMethod = new HttpPost( uriBuilder.build() ); vHttpMethod.setHeader( "Content-Type", "text/xml;charset=UTF-8" ); String soapAction = "\"" + meta.getOperationNamespace(); if ( !meta.getOperationNamespace().endsWith( "/" ) ) { soapAction += "/"; } soapAction += meta.getOperationName() + "\""; logDetailed( BaseMessages.getString( PKG, "WebServices.Log.UsingRequestHeaderSOAPAction", soapAction ) ); vHttpMethod.setHeader( "SOAPAction", soapAction ); return vHttpMethod; } WebService( StepMeta aStepMeta, StepDataInterface aStepData, int value, TransMeta aTransMeta, Trans aTrans ); boolean processRow( StepMetaInterface metaInterface, StepDataInterface dataInterface ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final String NS_PREFIX; }### Answer: @Test( expected = URISyntaxException.class ) public void newHttpMethodWithInvalidUrl() throws URISyntaxException { webServiceStep.getHttpMethod( NOT_VALID_URL ); }
### Question: WebService extends BaseStep implements StepInterface { static String getLocationFrom( HttpPost method ) { Header locationHeader = method.getFirstHeader( "Location" ); return locationHeader.getValue(); } WebService( StepMeta aStepMeta, StepDataInterface aStepData, int value, TransMeta aTransMeta, Trans aTrans ); boolean processRow( StepMetaInterface metaInterface, StepDataInterface dataInterface ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final String NS_PREFIX; }### Answer: @Test public void getLocationFrom() { HttpPost postMethod = mock( HttpPost.class ); Header locationHeader = new BasicHeader( LOCATION_HEADER, TEST_URL ); doReturn( locationHeader ).when( postMethod ).getFirstHeader( LOCATION_HEADER ); assertEquals( TEST_URL, WebService.getLocationFrom( postMethod ) ); }
### Question: FragmentHandler extends AbstractXulEventHandler { protected String getFragment( DatabaseInterface database, String dbName, String extension, String defaultFragment ) { String fragment; String ext = ( extension == null ? "" : extension ); String databaseName = ( dbName == null ? "" : dbName ); String defaultFrag = ( defaultFragment == null ? "" : defaultFragment ); if ( database.getXulOverlayFile() != null ) { fragment = packagePath.concat( database.getXulOverlayFile() ).concat( ext ); } else { fragment = packagePath.concat( databaseName ).concat( ext ); } InputStream in = getClass().getClassLoader().getResourceAsStream( fragment.toLowerCase() ); if ( in == null ) { fragment = packagePath.concat( defaultFrag ); } return fragment; } FragmentHandler(); void refreshOptions(); Object getData(); void setData( Object arg0 ); }### Answer: @Test public void testGetFragment() throws Exception { DatabaseInterface dbInterface = mock( DatabaseInterface.class ); assertEquals( "org/pentaho/ui/database/", fragmentHandler.getFragment( dbInterface, null, null, null ) ); when( dbInterface.getXulOverlayFile() ).thenReturn( "overlay.xul" ); assertEquals( "org/pentaho/ui/database/", fragmentHandler.getFragment( dbInterface, null, null, null ) ); }
### Question: FragmentHandler extends AbstractXulEventHandler { protected void showMessage( String message ) { try { XulMessageBox box = (XulMessageBox) document.createElement( "messagebox" ); box.setMessage( message ); box.open(); } catch ( XulException e ) { System.out.println( "Error creating messagebox " + e.getMessage() ); } } FragmentHandler(); void refreshOptions(); Object getData(); void setData( Object arg0 ); }### Answer: @Test public void testShowMessage() throws Exception { XulMessageBox messageBox = mock( XulMessageBox.class ); when( document.createElement( "messagebox" ) ).thenReturn( messageBox ); fragmentHandler.showMessage( null ); when( document.createElement( "messagebox" ) ).thenThrow( new XulException() ); fragmentHandler.showMessage( "" ); }
### Question: Validator extends BaseStep implements StepInterface { KettleValidatorException assertNumeric( ValueMetaInterface valueMeta, Object valueData, Validation field ) throws KettleValueException { if ( valueMeta.isNumeric() || containsOnlyDigits( valueMeta.getString( valueData ) ) ) { return null; } return new KettleValidatorException( this, field, KettleValidatorException.ERROR_NON_NUMERIC_DATA, BaseMessages.getString( PKG, "Validator.Exception.NonNumericDataNotAllowed", field.getFieldName(), valueMeta.toStringMeta() ), field.getFieldName() ); } Validator( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); }### Answer: @Test public void assertNumeric_StringWithDigits() throws Exception { ValueMetaString metaString = new ValueMetaString( "string-with-digits" ); assertNull( "Strings with digits are allowed", validator.assertNumeric( metaString, "123", new Validation() ) ); } @Test public void assertNumeric_String() throws Exception { ValueMetaString metaString = new ValueMetaString( "string" ); assertNotNull( "General strings are not allowed", validator.assertNumeric( metaString, "qwerty", new Validation() ) ); }
### Question: SimpleMapping extends BaseStep implements StepInterface { public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { if ( getData().wasStarted ) { if ( !getData().mappingTrans.isFinished() ) { getData().mappingTrans.waitUntilFinished(); } getTrans().removeActiveSubTransformation( getStepname() ); if ( getData().mappingTrans.getErrors() > 0 ) { logError( BaseMessages.getString( PKG, "SimpleMapping.Log.ErrorOccurredInSubTransformation" ) ); setErrors( 1 ); } } super.dispose( smi, sdi ); } SimpleMapping( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void prepareMappingExecution(); static void addInputRenames( List<MappingValueRename> renameList, List<MappingValueRename> addRenameList ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); void stopRunning( StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface ); void stopAll(); Trans getMappingTrans(); void addRowListener( RowListener rowListener ); SimpleMappingData getData(); }### Answer: @Test public void testDispose() throws KettleException { when( stepMockHelper.trans.getErrors() ).thenReturn( 0 ); when( stepMockHelper.trans.isFinished() ).thenReturn( Boolean.FALSE ); simpleMpData.wasStarted = true; smp = new SimpleMapping( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); smp.init( stepMockHelper.initStepMetaInterface, simpleMpData ); smp.dispose( stepMockHelper.processRowsStepMetaInterface, simpleMpData ); verify( stepMockHelper.trans, times( 1 ) ).isFinished(); verify( stepMockHelper.trans, times( 1 ) ).waitUntilFinished(); verify( stepMockHelper.trans, times( 1 ) ).removeActiveSubTransformation( anyString() ); }
### Question: MondrianInputMeta extends BaseStepMeta implements StepMetaInterface { public StepDataInterface getStepData() { return new MondrianData(); } MondrianInputMeta(); DatabaseMeta getDatabaseMeta(); void setDatabaseMeta( DatabaseMeta database ); boolean isVariableReplacementActive(); void setVariableReplacementActive( boolean variableReplacementActive ); String getSQL(); void setSQL( String sql ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository, IMetaStore metaStore ); DatabaseMeta[] getUsedDatabaseConnections(); String getCatalog(); void setCatalog( String catalog ); String getRole(); void setRole( String role ); String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ); }### Answer: @Test public void testGetData() { MondrianInputMeta meta = new MondrianInputMeta(); assertTrue( meta.getStepData() instanceof MondrianData ); }
### Question: ReadAllCache implements DatabaseLookupData.Cache { @Override public void storeRowInCache( DatabaseLookupMeta meta, RowMetaInterface lookupMeta, Object[] lookupRow, Object[] add ) { throw new UnsupportedOperationException( "This cache is read-only" ); } ReadAllCache( DatabaseLookupData stepData, Object[][] keys, RowMetaInterface keysMeta, Object[][] data ); @Override Object[] getRowFromCache( RowMetaInterface lookupMeta, Object[] lookupRow ); @Override void storeRowInCache( DatabaseLookupMeta meta, RowMetaInterface lookupMeta, Object[] lookupRow, Object[] add ); }### Answer: @Test( expected = UnsupportedOperationException.class ) public void storeRowInCache_ThrowsException() throws Exception { buildCache( "" ).storeRowInCache( new DatabaseLookupMeta(), keysMeta.clone(), keys[ 0 ], data[ 0 ] ); }
### Question: DeserializedRow implements Row { @Override public Object[] getObjects() { return Collections.unmodifiableList( objects ).toArray(); } DeserializedRow( List<String> names, List<Class> types, List<Object> objects ); @Override List<String> getColumnNames(); @Override Object[] getObjects(); @Override boolean equals( Object o ); @Override int hashCode(); }### Answer: @Test public void testRow() throws Exception { Date date = new Date(); URI uri = new URI( "http: List<Object> objects = new ArrayList<>(); objects.add( 100 ); objects.add( 100.50 ); BigDecimal bigDecimal = new BigDecimal( "10000000000000000000.50" ); objects.add( bigDecimal ); objects.add( true ); objects.add( date ); objects.add( "A String" ); objects.add( uri ); List<String> names = new ArrayList<>(); names.add( "some int" ); names.add( "some Double" ); names.add( "some Decimal" ); names.add( "some Boolean" ); names.add( "some Date" ); names.add( "some String" ); names.add( "some Serializable" ); List<Class> classes = Arrays .asList( Integer.class, Double.class, BigDecimal.class, Boolean.class, Date.class, String.class, Object.class ); Row row = new DeserializedRow( names, classes, objects ); assertEquals( new Integer( 100 ), row.getObjects()[ 0 ] ); assertEquals( 100.50, (double) row.getObjects()[ 1 ], 0.001D ); assertEquals( bigDecimal, row.getObjects()[ 2 ] ); assertTrue( (Boolean) row.getObjects()[ 3 ] ); assertEquals( date, row.getObjects()[ 4 ] ); assertEquals( "A String", row.getObjects()[ 5 ] ); assertEquals( uri, row.getObjects()[ 6 ] ); }
### Question: Messages { public static ResourceBundle getBundle() { if ( RESOURCE_BUNDLE == null ) { RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); } return RESOURCE_BUNDLE; } private Messages(); static ResourceBundle getBundle(); static String getString( String key ); static String getString( String key, String param1 ); static String getString( String key, String param1, String param2 ); static String getString( String key, String param1, String param2, String param3 ); static String getString( String key, String param1, String param2, String param3, String param4 ); }### Answer: @Test public void testGetBundle() throws Exception { assertNotNull( Messages.getBundle() ); }
### Question: ActingPrincipal implements Principal, Serializable { public boolean equals( Object other ) { if ( other instanceof ActingPrincipal ) { ActingPrincipal that = (ActingPrincipal) other; return ( this.isAnonymous() && that.isAnonymous() ) || ( this.getName() != null && this.getName().equals( that.getName() ) ); } else { return false; } } ActingPrincipal( String name ); private ActingPrincipal(); @Override String getName(); boolean equals( Object other ); String toString(); int hashCode(); boolean isAnonymous(); static final ActingPrincipal ANONYMOUS; }### Answer: @Test public void equals() throws Exception { principal1 = new ActingPrincipal( "suzy" ); principal2 = new ActingPrincipal( "joe" ); assertFalse( principal1.equals( principal2 ) ); assertFalse( principal1.equals( ActingPrincipal.ANONYMOUS ) ); principal2 = new ActingPrincipal( "suzy" ); assertTrue( principal1.equals( principal2 ) ); principal2 = ActingPrincipal.ANONYMOUS; assertTrue( principal2.equals( ActingPrincipal.ANONYMOUS ) ); }
### Question: AccessOutputData extends BaseStepData implements StepDataInterface { void createDatabase( File databaseFile ) throws IOException { db = Database.create( databaseFile ); } AccessOutputData(); public Database db; public Table table; public List<Object[]> rows; public RowMetaInterface outputRowMeta; public boolean oneFileOpened; }### Answer: @Test public void testCreateDatabase() throws IOException { assertNull( data.db ); data.createDatabase( mdbFile ); assertNotNull( data.db ); assertTrue( mdbFile.exists() ); assertNull( data.table ); data.truncateTable(); assertNull( data.table ); data.closeDatabase(); }