### Question:
ApplicationMenuItemConverter { public ApplicationMenuItem toApplicationMenuItem(final ApplicationMenu applicationMenu) { final ApplicationMenuItem item = new ApplicationMenuItem(); item.setId(applicationMenu.getId()); item.setApplicationId(applicationMenu.getApplicationId()); item.setDisplayName(applicationMenu.getDisplayName()); if (applicationMenu.getApplicationPageId() != null) { item.setApplicationPageId(applicationMenu.getApplicationPageId()); } else { item.setApplicationPageId("-1"); } if (applicationMenu.getParentId() != null) { item.setParentMenuId(applicationMenu.getParentId()); } else { item.setParentMenuId("-1"); } item.setMenuIndex(applicationMenu.getIndex()); return item; }  ApplicationMenuItem toApplicationMenuItem(final ApplicationMenu applicationMenu); ApplicationMenuCreator toApplicationMenuCreator(final ApplicationMenuItem item); ApplicationMenuUpdater toApplicationMenuUpdater(final Map<String, String> attributes);  }### Answer:
@Test public void toApplicationMenuItem_should_map_all_fields() throws Exception { final ApplicationMenuImpl applicationMenu = new ApplicationMenuImpl(DISPLAY_NAME, APPLICATION_ID, APPLICATION_PAGE_ID, INDEX); applicationMenu.setParentId(PARENT_MENU_ID); applicationMenu.setId(MENU_ID); final ApplicationMenuItem item = converter.toApplicationMenuItem(applicationMenu); assertThat(item).isNotNull(); assertThat(item.getId().toLong()).isEqualTo(MENU_ID); assertThat(item.getDisplayName()).isEqualTo(DISPLAY_NAME); assertThat(item.getApplicationId().toLong()).isEqualTo(APPLICATION_ID); assertThat(item.getApplicationPageId().toLong()).isEqualTo(APPLICATION_PAGE_ID); assertThat(item.getParentMenuId().toLong()).isEqualTo(PARENT_MENU_ID); assertThat(item.getMenuIndex()).isEqualTo(INDEX); }
@Test public void applicationMenuItem_with_null_parent_id_should_not_return_null() throws Exception { final ApplicationMenuImpl applicationMenu = new ApplicationMenuImpl(DISPLAY_NAME, APPLICATION_ID, APPLICATION_PAGE_ID, INDEX); applicationMenu.setParentId(null); applicationMenu.setId(MENU_ID); final ApplicationMenuItem item = converter.toApplicationMenuItem(applicationMenu); assertThat(item.getAttributeValue(ApplicationMenuItem.ATTRIBUTE_PARENT_MENU_ID)).isEqualTo("-1"); }
@Test public void applicationMenuItem_with_null_page_id_should_not_return_null() throws Exception { final ApplicationMenuImpl applicationMenu = new ApplicationMenuImpl(DISPLAY_NAME, APPLICATION_ID, null, INDEX); applicationMenu.setParentId(PARENT_MENU_ID); applicationMenu.setId(MENU_ID); final ApplicationMenuItem item = converter.toApplicationMenuItem(applicationMenu); assertThat(item).isNotNull(); assertThat(item.getAttributeValue(ApplicationMenuItem.ATTRIBUTE_APPLICATION_PAGE_ID)).isEqualTo("-1"); }