@Test public void testCopyTemplate() { final String newTemplateName = "NewTemplateName"; doAnswer( new Answer<Void>() { @Override public Void answer( final InvocationOnMock invocation ) throws Throwable { final ParameterizedCommand command = (ParameterizedCommand) invocation.getArguments()[ 0 ]; if ( command != null ) { command.execute( newTemplateName ); } return null; } } ).when( copyPresenter ).copy( any( ParameterizedCommand.class ) ); final ServerTemplate serverTemplate = new ServerTemplate( "ServerTemplateKeyId", "ServerTemplateKeyName" ); presenter.setup( serverTemplate, null ); assertEquals( serverTemplate, presenter.getCurrentServerTemplate() ); presenter.copyTemplate(); verify( specManagementService ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName ); verify( copyPresenter ).hide(); final ArgumentCaptor<ServerTemplateListRefresh> serverTemplateCaptor = ArgumentCaptor.forClass( ServerTemplateListRefresh.class ); verify( serverTemplateListRefreshEvent ).fire( serverTemplateCaptor.capture() ); assertEquals( newTemplateName, serverTemplateCaptor.getValue().getSelectServerTemplateId() ); doThrow( new RuntimeException() ).when( specManagementService ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName ); presenter.copyTemplate(); verify( specManagementService, times( 2 ) ).copyServerTemplate( serverTemplate.getId(), newTemplateName, newTemplateName ); verify( copyPresenter ).errorDuringProcessing( anyString() ); }
public void copyTemplate() { copyPresenter.copy( new ParameterizedCommand<String>() { @Override public void execute( final String value ) { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { copyPresenter.hide(); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh( value ) ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { copyPresenter.errorDuringProcessing( view.getCopyTemplateErrorMessage() ); return false; } } ).copyServerTemplate( serverTemplate.getId(), value, value ); } } ); }
ServerTemplatePresenter { public void copyTemplate() { copyPresenter.copy( new ParameterizedCommand<String>() { @Override public void execute( final String value ) { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { copyPresenter.hide(); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh( value ) ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { copyPresenter.errorDuringProcessing( view.getCopyTemplateErrorMessage() ); return false; } } ).copyServerTemplate( serverTemplate.getId(), value, value ); } } ); } }
ServerTemplatePresenter { public void copyTemplate() { copyPresenter.copy( new ParameterizedCommand<String>() { @Override public void execute( final String value ) { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { copyPresenter.hide(); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh( value ) ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { copyPresenter.errorDuringProcessing( view.getCopyTemplateErrorMessage() ); return false; } } ).copyServerTemplate( serverTemplate.getId(), value, value ); } } ); } @Inject  ServerTemplatePresenter( final Logger logger,
                                    final View view,
                                    final CopyPopupPresenter copyPresenter,
                                    final Caller<SpecManagementService> specManagementService,
                                    final Event<NotificationEvent> notification,
                                    final Event<AddNewContainer> addNewContainerEvent,
                                    final Event<ContainerSpecSelected> containerSpecSelectedEvent,
                                    final Event<ServerInstanceSelected> serverInstanceSelectedEvent,
                                    final Event<ServerTemplateListRefresh> serverTemplateListRefreshEvent ); }
ServerTemplatePresenter { public void copyTemplate() { copyPresenter.copy( new ParameterizedCommand<String>() { @Override public void execute( final String value ) { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { copyPresenter.hide(); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh( value ) ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { copyPresenter.errorDuringProcessing( view.getCopyTemplateErrorMessage() ); return false; } } ).copyServerTemplate( serverTemplate.getId(), value, value ); } } ); } @Inject  ServerTemplatePresenter( final Logger logger,
                                    final View view,
                                    final CopyPopupPresenter copyPresenter,
                                    final Caller<SpecManagementService> specManagementService,
                                    final Event<NotificationEvent> notification,
                                    final Event<AddNewContainer> addNewContainerEvent,
                                    final Event<ContainerSpecSelected> containerSpecSelectedEvent,
                                    final Event<ServerInstanceSelected> serverInstanceSelectedEvent,
                                    final Event<ServerTemplateListRefresh> serverTemplateListRefreshEvent ); @PostConstruct void init(); View getView(); ServerTemplate getCurrentServerTemplate(); void setup( final ServerTemplate serverTemplate,
                       final ContainerSpec firstContainerSpec ); void onContainerSelect( @Observes final ContainerSpecSelected containerSpecSelected ); void onServerInstanceSelect( @Observes final ServerInstanceSelected serverInstanceSelected ); void onServerInstanceUpdated( @Observes final ServerInstanceUpdated serverInstanceUpdated ); void onServerInstanceDeleted( @Observes final ServerInstanceDeleted serverInstanceDeleted ); void addNewContainer(); void copyTemplate(); void removeTemplate(); }
ServerTemplatePresenter { public void copyTemplate() { copyPresenter.copy( new ParameterizedCommand<String>() { @Override public void execute( final String value ) { specManagementService.call( new RemoteCallback<Void>() { @Override public void callback( final Void aVoid ) { copyPresenter.hide(); serverTemplateListRefreshEvent.fire( new ServerTemplateListRefresh( value ) ); } }, new ErrorCallback<Object>() { @Override public boolean error( final Object o, final Throwable throwable ) { copyPresenter.errorDuringProcessing( view.getCopyTemplateErrorMessage() ); return false; } } ).copyServerTemplate( serverTemplate.getId(), value, value ); } } ); } @Inject  ServerTemplatePresenter( final Logger logger,
                                    final View view,
                                    final CopyPopupPresenter copyPresenter,
                                    final Caller<SpecManagementService> specManagementService,
                                    final Event<NotificationEvent> notification,
                                    final Event<AddNewContainer> addNewContainerEvent,
                                    final Event<ContainerSpecSelected> containerSpecSelectedEvent,
                                    final Event<ServerInstanceSelected> serverInstanceSelectedEvent,
                                    final Event<ServerTemplateListRefresh> serverTemplateListRefreshEvent ); @PostConstruct void init(); View getView(); ServerTemplate getCurrentServerTemplate(); void setup( final ServerTemplate serverTemplate,
                       final ContainerSpec firstContainerSpec ); void onContainerSelect( @Observes final ContainerSpecSelected containerSpecSelected ); void onServerInstanceSelect( @Observes final ServerInstanceSelected serverInstanceSelected ); void onServerInstanceUpdated( @Observes final ServerInstanceUpdated serverInstanceUpdated ); void onServerInstanceDeleted( @Observes final ServerInstanceDeleted serverInstanceDeleted ); void addNewContainer(); void copyTemplate(); void removeTemplate();  }