DataServiceRemapStepChooserDialogController extends AbstractController { public void init() throws InvocationTargetException, XulException { model.setServiceStep( stepNames.get( 0 ) ); ( (XulLabel) getElementById( "label1" ) ) .setValue( BaseMessages.getString( PKG, "RemapStepChooserDialog.Label", dataService.getName() ) ); SwtListbox steps = getElementById( "trans-steps" ); steps.setElements( stepNames ); BindingFactory bindingFactory = getBindingFactory(); bindingFactory.setBindingType( Binding.Type.BI_DIRECTIONAL ); bindingFactory.createBinding( model, "serviceStep", steps, "selectedItem" ).fireSourceChanged(); } 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 testInit() throws InvocationTargetException, XulException { DataServiceRemapStepChooserModel model = mock( DataServiceRemapStepChooserModel.class ); DataServiceMeta dataService = mock( DataServiceMeta.class ); List<String> stepNames = Arrays.asList( "step1" ); DataServiceDelegate delegate = mock( DataServiceDelegate.class ); final SwtLabel label = mock( SwtLabel.class ); final SwtListbox listbox = mock( SwtListbox.class ); BindingFactory bindingFactory = mock( BindingFactory.class ); when( bindingFactory.createBinding( same( model ), anyString(), any( XulComponent.class ), anyString() ) ) .thenReturn( mock( Binding.class ) ); DataServiceRemapStepChooserDialogController controller = spy( new DataServiceRemapStepChooserDialogController( model, dataService, stepNames, delegate ) ); doAnswer( new Answer() { private Object[] returnValues = { label, listbox }; int invocations = 0; @Override public Object answer( InvocationOnMock invocationOnMock ) throws Throwable { return returnValues[invocations++]; } } ).when( controller ).getElementById( anyString() ); doReturn( bindingFactory ).when( controller ).getBindingFactory(); controller.init(); verify( label ).setValue( anyString() ); verify( listbox ).setElements( same( stepNames ) ); verify( bindingFactory ).createBinding( same( model ), anyString(), same( listbox ), anyString() ); }