### Question:
ZkTreeModel extends DefaultTreeModel<E> { public E getSelectedData(@Nonnegative int depth) { int[] selectionPath = getSelectionPath(); if (selectionPath == null) { return null; } if (selectionPath.length <= depth) { throw new IndexOutOfBoundsException("There is no selection with level: " + depth + " in the tree. Selected path: " + Arrays.toString(selectionPath)); } return getChildData(Arrays.copyOf(selectionPath, depth + 1)); } ZkTreeModel(@Nonnull TreeNode<E> root); TreeNode<E> find(@Nonnull E data); @Override TreeNode<E> getChild(int... path); E getChildData(int... path); E getSelectedData(@Nonnegative int depth); TreeNode<E> removeSelected(); TreeNode<E> removeChild(int... path); ZkTreeNode<E> addExpandableNode(E data, int... parentNodePath); void dropNodeBefore(TreeNode<E> node, TreeNode<E> target); void dropNodeIn(TreeNode<E> node, TreeNode<E> target); void setSelectedNode(TreeNode<E> node);  }### Answer:
@Test public void testGetSelectedData() throws Exception { sut.addSelectionPath(new int[]{1, 0}); Object selectedData = sut.getSelectedData(1); assertSame(selectedData, sut.getChild(1, 0).getData()); }
@Test(expectedExceptions = IndexOutOfBoundsException.class) public void getSelectedDataShouldThrowWithTooLargeDepth() throws Exception { sut.addSelectionPath(new int[]{1}); sut.getSelectedData(1); }
@Test public void getSelectedDataWhenNothingIsSelected() throws Exception { assertNull(sut.getSelectedData(1)); }