@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 ); assertFalse( controller.isDatabaseWithNameExist( databaseMeta1, false ) ); databaseMeta2.setName( "TestDB1" ); assertTrue( controller.isDatabaseWithNameExist( databaseMeta2, false ) ); final DatabaseMeta databaseMeta3 = new DatabaseMeta(); databaseMeta3.setName( "TestDB3" ); assertFalse( controller.isDatabaseWithNameExist( databaseMeta3, true ) ); databaseMeta3.setName( "TestDB1" ); assertTrue( controller.isDatabaseWithNameExist( databaseMeta3, true ) ); }
@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 ) { return true; } } } return false; }
RepositoryConnectController { @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 ) { return true; } } } return false; } }
RepositoryConnectController { @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 ) { return true; } } } return false; } RepositoryConnectController( PluginRegistry pluginRegistry, Supplier<Spoon> spoonSupplier,
                                      RepositoriesMeta repositoriesMeta );  RepositoryConnectController(); }
RepositoryConnectController { @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 ) { return true; } } } return false; } RepositoryConnectController( PluginRegistry pluginRegistry, Supplier<Spoon> spoonSupplier,
                                      RepositoriesMeta repositoriesMeta );  RepositoryConnectController(); @SuppressWarnings( "unchecked" ) String getPlugins(); boolean createRepository( String id, Map<String, Object> items ); @SuppressWarnings( "unchecked" ) String getRepositories(); String getRepository( String name ); DatabaseMeta getDatabase( String name ); void removeDatabase( String name ); @SuppressWarnings( "unchecked" ) String getDatabases(); void connectToRepository(); void connectToRepository( String username, String password ); void connectToRepository( RepositoryMeta repositoryMeta ); void connectToRepository( RepositoryMeta repositoryMeta, String username, String password ); void reconnectToRepository( String username, String password ); boolean deleteRepository( String name ); void addDatabase( DatabaseMeta databaseMeta ); boolean setDefaultRepository( String name ); String getDefaultUrl(); String getCurrentUser(); void setCurrentRepository( RepositoryMeta repositoryMeta ); RepositoryMeta getCurrentRepository(); RepositoryMeta getConnectedRepository(); void setConnectedRepository( RepositoryMeta connectedRepository ); RepositoryMeta getDefaultRepositoryMeta(); RepositoryMeta getRepositoryMetaByName( String name ); boolean isConnected( String name ); boolean isConnected(); Repository getConnectedRepositoryInstance(); void save(); PropsUI getPropsUI(); void addListener( RepositoryContollerListener listener ); void fireListeners(); boolean isRelogin(); void setRelogin( boolean relogin ); Map<String, Object> modelToMap( RepositoryModel model ); }
RepositoryConnectController { @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 ) { return true; } } } return false; } RepositoryConnectController( PluginRegistry pluginRegistry, Supplier<Spoon> spoonSupplier,
                                      RepositoriesMeta repositoriesMeta );  RepositoryConnectController(); @SuppressWarnings( "unchecked" ) String getPlugins(); boolean createRepository( String id, Map<String, Object> items ); @SuppressWarnings( "unchecked" ) String getRepositories(); String getRepository( String name ); DatabaseMeta getDatabase( String name ); void removeDatabase( String name ); @SuppressWarnings( "unchecked" ) String getDatabases(); void connectToRepository(); void connectToRepository( String username, String password ); void connectToRepository( RepositoryMeta repositoryMeta ); void connectToRepository( RepositoryMeta repositoryMeta, String username, String password ); void reconnectToRepository( String username, String password ); boolean deleteRepository( String name ); void addDatabase( DatabaseMeta databaseMeta ); boolean setDefaultRepository( String name ); String getDefaultUrl(); String getCurrentUser(); void setCurrentRepository( RepositoryMeta repositoryMeta ); RepositoryMeta getCurrentRepository(); RepositoryMeta getConnectedRepository(); void setConnectedRepository( RepositoryMeta connectedRepository ); RepositoryMeta getDefaultRepositoryMeta(); RepositoryMeta getRepositoryMetaByName( String name ); boolean isConnected( String name ); boolean isConnected(); Repository getConnectedRepositoryInstance(); void save(); PropsUI getPropsUI(); void addListener( RepositoryContollerListener listener ); void fireListeners(); boolean isRelogin(); void setRelogin( boolean relogin ); Map<String, Object> modelToMap( RepositoryModel model ); static final String DISPLAY_NAME; static final String DESCRIPTION; static final String IS_DEFAULT; static final String URL; static final String DATABASE_CONNECTION; static final String SHOW_HIDDEN_FOLDERS; static final String LOCATION; static final String DO_NOT_MODIFY; static final String DEFAULT_URL; static final String ERROR_401; }