SynchronizationListener implements ContentChangedListener, StepMetaChangeListenerInterface { @Override public void contentSafe( Object parentObject ) { synchronizer.sync( (TransMeta) parentObject, ( e ) -> { String message = e.getMessage(); if ( prompt ) { if ( e instanceof DataServiceAlreadyExistsException ) { DataServiceMeta dataService = ( (DataServiceAlreadyExistsException) e ).getDataServiceMeta(); delegate.syncExec( suggestEdit( dataService, message ) ); } if ( e instanceof UndefinedDataServiceException ) { DataServiceMeta dataService = ( (UndefinedDataServiceException) e ).getDataServiceMeta(); delegate.syncExec( suggestRemove( dataService, message ) ); } } delegate.getLogChannel().logError( message, e ); return null; } ); } SynchronizationListener( DataServiceDelegate delegate,
                                  DataServiceReferenceSynchronizer synchronizer ); @Override void contentChanged( Object parentObject ); @Override void contentSafe( Object parentObject ); @Override void onStepChange( TransMeta transMeta, StepMeta oldMeta, StepMeta newMeta ); void install( TransMeta transMeta ); boolean isPrompt(); void setPrompt( boolean prompt );  }
@Test public void testContentSafe() throws Exception { service.contentSafe( transMeta ); verify( synchronizer ).sync( same( transMeta ), errorHandler.capture() ); UndefinedDataServiceException undefinedException = new UndefinedDataServiceException( dataServiceMeta ); when( delegate.showPrompt( anyString(), anyString() ) ).thenReturn( false, true ); errorHandler.getValue().apply( undefinedException ); verify( delegate, never() ).removeDataService( dataServiceMeta, false ); errorHandler.getValue().apply( undefinedException ); verify( delegate ).removeDataService( dataServiceMeta ); verify( logChannel, times( 2 ) ).logError( anyString(), same( undefinedException ) ); DataServiceAlreadyExistsException conflictException = new DataServiceAlreadyExistsException( dataServiceMeta ); errorHandler.getValue().apply( conflictException ); verify( delegate ).suggestEdit( same( dataServiceMeta ), anyString(), anyString() ); verify( logChannel ).logError( anyString(), same( conflictException ) ); MetaStoreException metaStoreException = new MetaStoreException(); errorHandler.getValue().apply( metaStoreException ); verify( logChannel ).logError( anyString(), same( metaStoreException ) ); }