package ru.agolovin;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * @author agolovin (agolovin@list.ru)
 * @version $Id$
 * @since 0.1
 */
public class TreeTest {

    /**
     * Test.
     */
    @Test
    public void whenAddTwoSameParentThenResultTwoChild() {
        Tree<String> tree = new Tree<>();

        String parentOne = "par1";

        tree.add(parentOne, "childOne");
        tree.add(parentOne, "childTwo");
        tree.add(parentOne, "childThree");
        tree.add(parentOne, "childFour");

        List<String> answer = new ArrayList<>();
        answer.add("childOne");
        answer.add("childTwo");
        answer.add("childThree");
        answer.add("childFour");

        assertThat(tree.getChild(parentOne), is(answer));
    }

    /**
     * Test iterator.
     */
    @Test
    public void whenIteratorWork() {
        Tree<String> tree = new Tree<>();

        String parentOne = "par1";

        tree.add(parentOne, "childOne");
        tree.add(parentOne, "childTwo");

        Iterator<String> iter = tree.iterator();

        assertThat(iter.hasNext(), is(true));
        assertThat(iter.next(), is("par1"));
        assertThat(iter.hasNext(), is(false));
    }
}

@@ -1049,32 +1049,67 @@
 entOne = %22par1%22;
+%0A        String parentTwo = %22par2%22;
 %0A%0A        tree.a
@@ -1175,16 +1175,98 @@
 ldTwo%22);
+%0A        tree.add(parentTwo, %22childTwo%22);%0A        tree.add(parentTwo, %22childTwo%22);
 %0A%0A      
@@ -1351,24 +1351,24 @@
  is(true));%0A
-
         asse
@@ -1396,24 +1396,69 @@
 s(%22par1%22));%0A
+        assertThat(iter.next(), is(%22par2%22));%0A
         asse

add task1 in part6 chapter5 package2