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;
  }
@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() );
  }