DataServiceDialog { protected DataServiceDialog initOptimizations( List<PushDownFactory> pushDownFactories ) throws KettleException { ImmutableList<OptimizationOverlay> overlays = FluentIterable.from( pushDownFactories ) .transform( new Function<PushDownFactory, OptimizationOverlay>() { @Override public OptimizationOverlay apply( PushDownFactory input ) { return input.createOverlay(); } } ) .filter( Predicates.notNull() ) .toSortedList( Ordering.natural().onResultOf( new Function<OptimizationOverlay, Comparable>() { @Override public Comparable apply( OptimizationOverlay input ) { return input.getPriority(); } } ) ); for ( OptimizationOverlay overlay : overlays ) { overlay.apply( this ); } XulTabbox optimizationTabs = controller.getElementById( "optimizationTabs" ); if ( optimizationTabs.getTabs().getTabCount() > 0 ) { optimizationTabs.setSelectedIndex( 0 ); } return this; } DataServiceDialog( DataServiceDialogController controller, DataServiceModel model ); XulDomContainer getXulDomContainer(); XulDomContainer applyOverlay( OptimizationOverlay overlay, String xulSource ); void open(); void close(); DataServiceDialogController getController(); DataServiceModel getModel();  }
@Test public void testInitOptimizations() throws Exception { PushDownFactory pushDownFactory; ArrayList<PushDownFactory> factories = Lists.newArrayList(); XulTabbox tabBox = mock( XulTabbox.class, RETURNS_DEEP_STUBS ); when( controller.getElementById( "optimizationTabs" ) ).thenReturn( tabBox ); when( tabBox.getTabs().getTabCount() ).thenReturn( 2 ); pushDownFactory = mock( PushDownFactory.class ); DataServiceDialog.OptimizationOverlay overlay1 = mock( DataServiceDialog.OptimizationOverlay.class ); when( pushDownFactory.createOverlay() ).thenReturn( overlay1 ); when( overlay1.getPriority() ).thenReturn( 100.0 ); factories.add( pushDownFactory ); pushDownFactory = mock( PushDownFactory.class ); DataServiceDialog.OptimizationOverlay overlay0 = mock( DataServiceDialog.OptimizationOverlay.class ); when( pushDownFactory.createOverlay() ).thenReturn( overlay0 ); when( overlay0.getPriority() ).thenReturn( 0.0 ); factories.add( pushDownFactory ); pushDownFactory = mock( PushDownFactory.class ); when( pushDownFactory.createOverlay() ).thenReturn( null ); factories.add( pushDownFactory ); dialog.initOptimizations( factories ); InOrder inOrder = inOrder( overlay0, overlay1 ); inOrder.verify( overlay0 ).apply( dialog ); inOrder.verify( overlay1 ).apply( dialog ); inOrder.verifyNoMoreInteractions(); verify( tabBox ).setSelectedIndex( 0 ); reset( tabBox ); when( tabBox.getTabs().getTabCount() ).thenReturn( 0 ); dialog.initOptimizations( factories ); verify( tabBox, times( 0 ) ).setSelectedIndex( 0 ); }