ParameterGenerationController extends AbstractController { public void editParameter() throws XulException { ParameterGeneration parameterGeneration = checkNotNull( model.getParameterGeneration() ); XulPromptBox promptBox = createPromptBox(); promptBox.setTitle( getString( PKG, "ParameterGenerationController.Edit.Title" ) ); promptBox.setMessage( getString( PKG, "ParameterGenerationController.Edit.Message" ) ); promptBox.setValue( parameterGeneration.getParameterName() ); ParameterEditor editor = new ParameterEditor( parameterGeneration ); promptBox.addDialogCallback( editor ); if ( promptBox.open() == 0 && editor.modified ) { model.updateParameterMap(); model.setSelectedParameter( parameterGeneration.getParameterName() ); } } ParameterGenerationController( ParameterGenerationFactory factory, ParameterGenerationModel model ); void initBindings( List<String> supportedSteps ); void runAutoGenerate(); void addParameter(); void editParameter(); void removeParameter();  }
@Test public void testEditParameter() throws Exception { PushDownOptimizationMeta meta = new PushDownOptimizationMeta(); ParameterGeneration parameterGeneration = new ParameterGeneration( factory ); parameterGeneration.setParameterName( "parameterName" ); setSelected( meta, parameterGeneration ); mockPromptBox( "newParameterName", XulDialogCallback.Status.ACCEPT ); controller.editParameter(); assertThat( parameterGeneration.getParameterName(), equalTo( "newParameterName" ) ); verify( model ).setSelectedParameter( "newParameterName" ); verify( model ).updateParameterMap(); }
@Test public void testEditParameterFailure() throws Exception { PushDownOptimizationMeta meta = new PushDownOptimizationMeta(); ParameterGeneration parameterGeneration = new ParameterGeneration( factory ); parameterGeneration.setParameterName( "parameterName" ); setSelected( meta, parameterGeneration ); mockPromptBox( "newParameterName", XulDialogCallback.Status.CANCEL ); controller.editParameter(); mockPromptBox( "parameterName", XulDialogCallback.Status.ACCEPT ); controller.editParameter(); mockPromptBox( "", XulDialogCallback.Status.ACCEPT ); controller.editParameter(); mockPromptBox( "newParameterName", XulDialogCallback.Status.ACCEPT ); when( model.getParameterMap() ).thenReturn( ImmutableMap.of( "parameterName", meta, "newParameterName", mock( PushDownOptimizationMeta.class ) ) ); controller.editParameter(); assertThat( parameterGeneration.getParameterName(), equalTo( "parameterName" ) ); verify( model, never() ).updateParameterMap(); verify( messageBox, times( 2 ) ).setIcon( SWT.ICON_WARNING ); verify( messageBox, times( 2 ) ).open(); }