210211212213214215216217218219220
Menu item = menu.addItem( "path2" ); item.addItem( "sub1" ); Menu subItem = item.addItem( "sub2" ); subItem.addItem( "subsub1" ).setSelected( true ); subItem.addItem( "subsub2" ); menu.getItemWithPath( "sub1" ).setSelected( true ); assertFalse( menu.getItemWithPath( "path1" ).isSelected() ); assertTrue( menu.getItemWithPath( "path2" ).isSelected() );
225226227228229230231232233234235
} @Test public void selectedItemIsAlwaysLookedForInTheSubtree() { Menu menu = new Menu(); menu.addItem( "path1" ); Menu item = menu.addItem( "path2" ); item.addItem( "sub1" ); Menu subItem = item.addItem( "sub2" );
228229230231232233234235236237238
public void selectedItemIsAlwaysLookedForInTheSubtree() { Menu menu = new Menu(); menu.addItem( "path1" ); Menu item = menu.addItem( "path2" ); item.addItem( "sub1" ); Menu subItem = item.addItem( "sub2" ); subItem.addItem( "subsub1" ).setSelected( true ); subItem.addItem( "subsub2" );
231232233234235236237238239240241
Menu item = menu.addItem( "path2" ); item.addItem( "sub1" ); Menu subItem = item.addItem( "sub2" ); subItem.addItem( "subsub1" ).setSelected( true ); subItem.addItem( "subsub2" ); Menu selected = menu.getSelectedItem(); assertSame( item, selected );
232233234235236237238239240241242
Menu item = menu.addItem( "path2" ); item.addItem( "sub1" ); Menu subItem = item.addItem( "sub2" ); subItem.addItem( "subsub1" ).setSelected( true ); subItem.addItem( "subsub2" ); Menu selected = menu.getSelectedItem(); assertSame( item, selected ); selected = menu.getLowestSelectedItem();
251252253254255256257258259260261
} @Test public void selectedItemPathIfNoneSelected() { Menu menu = new Menu(); menu.addItem( "one" ); assertNull( menu.getSelectedItem() ); assertTrue( menu.getSelectedItemPath().isEmpty() ); }
260261262263264265266267268269270
} @Test public void selectedItemPathIfRootSelected() { Menu menu = new Menu(); menu.addItem( "one" ); menu.setSelected( true ); assertNull( menu.getSelectedItem() ); List<Menu> items = menu.getSelectedItemPath();
274275276277278279280281282283284
@Test public void selectedItemPathIfLowerSelected() { Menu menu = new Menu(); Menu item = menu.addItem( "one" ); item.addItem( "sub-one" ); Menu subTwo = item.addItem( "sub-two" ); subTwo.setSelected( true ); List<Menu> items = menu.getSelectedItemPath();
297298299300301302303304305306307
public void mergeMenu() { @SuppressWarnings("unchecked") Comparator<Menu> mockComparator = mock( Comparator.class ); Menu menu = new Menu(); menu.addItem( "path1" ); Menu item = menu.addItem( "path2" ); item.setAttribute( "myattribute", "myvalue" ); item.setAttribute( "myattribute2", "myvalue" );
109110111112113114115116117118119
public void orderedMenuIsNotSorted() { Menu menu = new Menu( "any" ); menu.setOrdered( true ); menu.addItem( "/aaa", "ccc" ); menu.addItem( "/bbb", "aaa" ); menu.addItem( "/ccc", "bbb" ); menu.sort(); assertMenu( menu, "ccc", "aaa", "bbb" ); }