DataServiceDialogController extends AbstractController { public void saveAndClose() throws XulException { try { if ( dataServiceHasNoName( model ) ) { return; } String existing = dataService != null ? dataService.getName() : null; delegate.save( delegate.checkConflict( delegate.checkDefined( model.getDataService() ), existing ) ); if ( dataService != null && !model.getServiceName().equals( existing ) ) { delegate.removeDataService( dataService ); } delegate.createSyncService().install( model.getTransMeta() ); close(); } catch ( DataServiceValidationException e ) { error( getString( PKG, "DataServiceDialog.SaveError.Title" ), e.getMessage() ); } catch ( Exception e ) { error( getString( PKG, "DataServiceDialog.SaveError.Title" ), e.getMessage() ); getLogChannel().logError( e.getMessage(), e ); } } DataServiceDialogController( DataServiceModel model, DataServiceDelegate delegate ); void init(); void showTestDialog(); void saveAndClose(); void open(); void close(); @SuppressWarnings( "unused" ) // Bound via XUL void showHelp(); @SuppressWarnings( "unused" ) // Bound via XUL void showDriverDetailsDialog(); void setDataService( DataServiceMeta dataService ); static final String XUL_DIALOG_ID; }
@Test public void testSaveAndClose() throws Exception { DataServiceMeta editingDataService = mock( DataServiceMeta.class ); controller.setDataService( editingDataService ); when( editingDataService.getName() ).thenReturn( EDITING_SERVICE_NAME ); when( delegate.checkDefined( dataServiceMeta ) ).thenReturn( dataServiceMeta ); when( delegate.checkConflict( dataServiceMeta, EDITING_SERVICE_NAME ) ).thenReturn( dataServiceMeta ); controller.saveAndClose(); verify( delegate ).save( dataServiceMeta ); verify( delegate ).removeDataService( editingDataService ); verify( synchronizationListener ).install( transMeta ); verify( dialog ).dispose(); }
@Test public void testSaveAndCloseNoName() throws Exception { DataServiceMeta editingDataService = mock( DataServiceMeta.class ); when( model.getServiceName() ).thenReturn( null ); controller.saveAndClose(); verify( delegate, times( 0 ) ).save( dataServiceMeta ); verify( delegate, times( 0 ) ).removeDataService( editingDataService ); verify( synchronizationListener, times( 0 ) ).install( transMeta ); verify( dialog, times( 0 ) ).dispose(); }