DataServiceRemapStepChooserDialogController extends AbstractController { @SuppressWarnings( "unused" ) public void remap() { dataService.setStepname( model.getServiceStep() ); try { dataServiceDelegate.save( dataService ); action = DataServiceRemapStepChooserDialog.Action.REMAP; } catch ( Exception e ) { e.printStackTrace(); dataServiceDelegate.showError( "Error saving data service", "Error occurred while saving data service." ); action = DataServiceRemapStepChooserDialog.Action.CANCEL; } getDialog().dispose(); } DataServiceRemapStepChooserDialogController( DataServiceRemapStepChooserModel model,
      DataServiceMeta dataService,
      List<String> stepNames, DataServiceDelegate dataServiceDelegate ); void init(); @SuppressWarnings( "unused" ) // Bound via xul void remap(); void cancel(); DataServiceRemapStepChooserDialog.Action getAction();  }
@Test public void testRemap() throws Exception { DataServiceRemapStepChooserModel model = mock( DataServiceRemapStepChooserModel.class ); DataServiceMeta dataService = mock( DataServiceMeta.class ); List<String> stepNames = Arrays.asList( "step1", "step2" ); DataServiceDelegate delegate = mock( DataServiceDelegate.class ); SwtDialog dialog = mock( SwtDialog.class ); when( model.getServiceStep() ).thenReturn( "step2" ); doNothing().doThrow( Exception.class ).when( delegate ).save( any( DataServiceMeta.class ) ); DataServiceRemapStepChooserDialogController controller = spy( new DataServiceRemapStepChooserDialogController( model, dataService, stepNames, delegate ) ); doReturn( dialog ).when( controller ).getDialog(); controller.remap(); verify( dataService ).setStepname( "step2" ); verify( delegate ).save( same( dataService ) ); Assert.assertEquals( DataServiceRemapStepChooserDialog.Action.REMAP, controller.getAction() ); controller.remap(); verify( delegate ).showError( anyString(), anyString() ); Assert.assertEquals( DataServiceRemapStepChooserDialog.Action.CANCEL, controller.getAction() ); }