### Question:
PartitionSettings { public int getDefaultSelectedSchemaIndex() { List<String> schemaNames; try { schemaNames = schemasProvider.getPartitionSchemasNames( transMeta ); } catch ( KettleException e ) { schemaNames = Collections.emptyList(); } PartitionSchema partitioningSchema = stepMeta.getStepPartitioningMeta().getPartitionSchema(); int defaultSelectedSchemaIndex = 0; if ( partitioningSchema != null && partitioningSchema.getName() != null && !schemaNames.isEmpty() ) { defaultSelectedSchemaIndex = Const.indexOfString( partitioningSchema.getName(), schemaNames ); } return defaultSelectedSchemaIndex != -1 ? defaultSelectedSchemaIndex : 0; } PartitionSettings( int exactSize, TransMeta transMeta, StepMeta stepMeta,
                            PartitionSchemasProvider schemasProvider ); void fillOptionsAndCodesByPlugins( List<PluginInterface> plugins ); int getDefaultSelectedMethodIndex(); int getDefaultSelectedSchemaIndex(); String getMethodByMethodDescription( String methodDescription ); String[] getOptions(); String[] getCodes(); List<String> getSchemaNames(); String[] getSchemaNamesArray(); List<PartitionSchema> getSchemas(); StepMeta getStepMeta(); void updateMethodType( int methodType ); void updateMethod( String method ); void updateSchema( PartitionSchema schema ); void rollback( StepMeta before ); StepMeta getBefore(); StepMeta getAfter(); TransMeta getTransMeta();  }### Answer:
@Test public void defaultSelectedSchemaIndexIsFoundBySchemaName() throws Exception { PartitionSchema schema = new PartitionSchema( "qwerty", Collections.<String>emptyList() ); StepPartitioningMeta meta = mock( StepPartitioningMeta.class ); when( meta.getPartitionSchema() ).thenReturn( schema ); when( stepMeta.getStepPartitioningMeta() ).thenReturn( meta ); List<String> schemas = Arrays.asList( "1", plugin.getName(), "2" ); when( partitionSchemasProvider.getPartitionSchemasNames( any( TransMeta.class ) ) ).thenReturn( schemas ); assertEquals( 1, settings.getDefaultSelectedSchemaIndex() ); }
@Test public void defaultSelectedSchemaIndexWhenSchemaNameIsNotDefined() throws Exception { PartitionSchema schema = new PartitionSchema( ); StepPartitioningMeta meta = mock( StepPartitioningMeta.class ); when( meta.getPartitionSchema() ).thenReturn( schema ); when( stepMeta.getStepPartitioningMeta() ).thenReturn( meta ); List<String> schemas = Arrays.asList( "test" ); when( partitionSchemasProvider.getPartitionSchemasNames( any( TransMeta.class ) ) ).thenReturn( schemas ); assertEquals( 0, settings.getDefaultSelectedSchemaIndex() ); }
@Test public void defaultSelectedSchemaIndexIsNilWhenNotFoundBySchemaName() throws Exception { PartitionSchema schema = new PartitionSchema( "asdfg", Collections.<String>emptyList() ); StepPartitioningMeta meta = mock( StepPartitioningMeta.class ); when( meta.getPartitionSchema() ).thenReturn( schema ); when( stepMeta.getStepPartitioningMeta() ).thenReturn( meta ); List<String> schemas = Arrays.asList( "1", plugin.getName(), "2" ); when( partitionSchemasProvider.getPartitionSchemasNames( any( TransMeta.class ) ) ).thenReturn( schemas ); assertEquals( 0, settings.getDefaultSelectedSchemaIndex() ); }