ParameterGenerationController extends AbstractController { public void addParameter() throws XulException { PushDownOptimizationMeta meta = new PushDownOptimizationMeta(); ParameterGeneration parameterGeneration = factory.createPushDown(); meta.setType( parameterGeneration ); meta.setStepName( getStepMenuList().getSelectedItem() ); XulPromptBox promptBox = createPromptBox(); promptBox.setTitle( getString( PKG, "ParameterGenerationController.Create.Title" ) ); promptBox.setMessage( getString( PKG, "ParameterGenerationController.Create.Message" ) ); ParameterEditor editor = new ParameterEditor( parameterGeneration ); promptBox.addDialogCallback( editor ); if ( promptBox.open() == 0 && editor.modified ) { model.add( meta ); 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 testAddParameter() throws Exception { ParameterGeneration parameterGeneration = new ParameterGeneration( factory ); when( factory.createPushDown() ).thenReturn( parameterGeneration ); when( model.getParameterMap() ).thenReturn( ImmutableMap.<String, PushDownOptimizationMeta>of() ); when( stepList.getSelectedItem() ).thenReturn( "Default Step" ); mockPromptBox( "parameterName", XulDialogCallback.Status.ACCEPT ); controller.addParameter(); ArgumentCaptor<PushDownOptimizationMeta> optMetaCaptor = ArgumentCaptor.forClass( PushDownOptimizationMeta.class ); verify( model ).add( optMetaCaptor.capture() ); PushDownOptimizationMeta pushDownOptimizationMeta = optMetaCaptor.getValue(); assertThat( pushDownOptimizationMeta, allOf( hasProperty( "type", sameInstance( parameterGeneration ) ), hasProperty( "enabled", is( true ) ), hasProperty( "stepName", is( "Default Step" ) ) ) ); assertThat( parameterGeneration.getParameterName(), equalTo( "parameterName" ) ); verify( model ).setSelectedParameter( "parameterName" ); }
@Test public void testAddParameterFailure() throws Exception { when( factory.createPushDown() ).thenReturn( new ParameterGeneration( factory ) ); when( model.getParameterMap() ).thenReturn( ImmutableMap.<String, PushDownOptimizationMeta>of() ); when( stepList.getSelectedItem() ).thenReturn( "Default Step" ); mockPromptBox( "parameterName", XulDialogCallback.Status.CANCEL ); controller.addParameter(); mockPromptBox( "", XulDialogCallback.Status.ACCEPT ); controller.addParameter(); mockPromptBox( "parameterName", XulDialogCallback.Status.ACCEPT ); when( model.getParameterMap() ).thenReturn( ImmutableMap.of( "parameterName", mock( PushDownOptimizationMeta.class ) ) ); controller.addParameter(); verify( model, never() ).add( any( PushDownOptimizationMeta.class ) ); verify( messageBox, times( 2 ) ).setIcon( SWT.ICON_WARNING ); verify( messageBox, times( 2 ) ).open(); }