@Test
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" );
Menu other = new Menu();
other.setPath( "other" );
other.setTitle( "title other" );
other.setDisabled( true );
other.setGroup( true );
other.setAttribute( "myattribute", "myothervalue" );
other.setAttribute( "myotherattribute", "myothervalue" );
Menu otherItem = other.addItem( "otherItem" );
otherItem.setSelected( true );
otherItem.setUrl( "other item url" );
otherItem.setComparator( mockComparator, true );
// Merge into sub-tree
item.merge( other, false );
assertEquals( 2, menu.size() );
assertEquals( "path1", menu.getFirstItem().getPath() );
Menu modified = menu.getItems().get( 1 );
assertEquals( "other", modified.getPath() );
assertEquals( "title other", modified.getTitle() );
assertTrue( modified.isDisabled() );
assertTrue( modified.isGroup() );
assertEquals( 3, modified.getAttributes().size() );
assertEquals( "myothervalue", modified.getAttribute( "myattribute" ) );
assertEquals( "myvalue", modified.getAttribute( "myattribute2" ) );
assertEquals( "myothervalue", modified.getAttribute( "myotherattribute" ) );
assertTrue( modified.isSelected() );
assertEquals( 1, modified.size() );
modified = modified.getFirstItem();
assertEquals( "otherItem", modified.getPath() );
assertEquals( "other item url", modified.getUrl() );
assertTrue( modified.isSelected() );
assertSame( mockComparator, modified.getComparator() );
assertTrue( modified.isComparatorInheritable() );
}