@VisibleForTesting
  boolean isDatabaseWithNameExist( DatabaseMeta databaseMeta, boolean isNew ) {
    for ( int i = 0; i < repositoriesMeta.nrDatabases(); i++ ) {
      final DatabaseMeta iterDatabase = repositoriesMeta.getDatabase( i );
      if ( iterDatabase.getName().trim().equalsIgnoreCase( databaseMeta.getName().trim() ) ) {
        if ( isNew || databaseMeta != iterDatabase ) { // do not check the same instance
          return true;
        }
      }
    }
    return false;
  }
@Test
  public void testIsDatabaseWithNameExist() throws Exception {
    final DatabaseMeta databaseMeta1 = new DatabaseMeta();
    databaseMeta1.setName( "TestDB1" );
    controller.addDatabase( databaseMeta1 );
    final DatabaseMeta databaseMeta2 = new DatabaseMeta();
    databaseMeta2.setName( "TestDB2" );
    controller.addDatabase( databaseMeta2 );

    when( repositoriesMeta.nrDatabases() ).thenReturn( 2 );
    when( repositoriesMeta.getDatabase( 0 ) ).thenReturn( databaseMeta1 );
    when( repositoriesMeta.getDatabase( 1 ) ).thenReturn( databaseMeta2 );


    //existing databases
    assertFalse( controller.isDatabaseWithNameExist( databaseMeta1, false ) );
    databaseMeta2.setName( "TestDB1" );
    assertTrue( controller.isDatabaseWithNameExist( databaseMeta2, false ) );

    //new databases
    final DatabaseMeta databaseMeta3 = new DatabaseMeta();
    databaseMeta3.setName( "TestDB3" );
    assertFalse( controller.isDatabaseWithNameExist( databaseMeta3, true ) );
    databaseMeta3.setName( "TestDB1" );
    assertTrue( controller.isDatabaseWithNameExist( databaseMeta3, true ) );
  }