DataServicePopupMenuExtension implements ExtensionPointInterface { @Override public void callExtensionPoint( LogChannelInterface log, Object extension ) throws KettleException { Menu popupMenu = null; Tree selectionTree = (Tree) extension; TreeSelection[] objects = delegate.getSpoon().getTreeObjects( selectionTree ); TreeSelection object = objects[0]; Object selection = object.getSelection(); if ( selection == DataServiceMeta.class ) { popupMenu = uiFactory.getMenu( selectionTree ); createRootPopupMenu( popupMenu ); } else if ( selection instanceof DataServiceMeta ) { selectedDataService = (DataServiceMeta) selection; popupMenu = uiFactory.getMenu( selectionTree ); createItemPopupMenu( popupMenu ); } if ( popupMenu != null ) { ConstUI.displayMenu( popupMenu, selectionTree ); } else { selectionTree.setMenu( null ); } } DataServicePopupMenuExtension( DataServiceContext context ); @Override void callExtensionPoint( LogChannelInterface log, Object extension ); public DataServiceMeta selectedDataService; }
@Test public void testCallExtensionPointRoot() throws Exception { when( selection.getSelection() ).thenReturn( DataServiceMeta.class ); dataServicePopupMenuExtension.callExtensionPoint( log, extension ); verify( delegate, times( 2 ) ).getSpoon(); verify( spoon ).getTreeObjects( extension ); verify( uiFactory, times( 2 ) ).getMenuItem( menu, SWT.NONE ); }
@Test public void testCallExtensionPoint() throws Exception { when( uiFactory.getMenu( any( Tree.class ) ) ).thenReturn( null ); when( selection.getSelection() ).thenReturn( dataServiceMeta ); dataServicePopupMenuExtension.callExtensionPoint( log, extension ); verify( delegate, times( 2 ) ).getSpoon(); verify( spoon ).getTreeObjects( extension ); verify( uiFactory, times( 5 ) ).getMenuItem( null, SWT.NONE ); }