package ru.job4j.ProjectTracker;

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

/**
 * @since 10.05.2017
 */
public class FindTest {
        /** Test 1 of many.  */
        @Test
        public void testFindById() {
            Tracker tracker = new Tracker();
            Item item = tracker.add(new Item("name01", "desc01", 101));
            Assert.assertEquals(item.getId(), tracker.findById(item.getId()).getId());
        }
    /** Test 1 of many.  */
        @Test
        public void testAddAndFindByName() {
            Tracker tracker = new Tracker();
            Item item = tracker.add(new Item("name01", "desc01", 101));
            item = tracker.add(new Item("name02", "desc02", 102));
            Item itemSecond = tracker.findByName("name02")[0];
            Assert.assertEquals(itemSecond.getName(), (tracker.findByName("name02")[0].getName()));
        }
    /** Test 1 of many.  */
    @Test
    public void testAddAndFindAll() {
        Tracker tracker = new Tracker();
        Item item = tracker.add(new Item("name01", "desc01", 101));
        item = tracker.add(new Item("name02", "desc02", 102));
        item = tracker.add(new Item("name03", "desc03", 103));
        item = tracker.add(new Item("name03", "desc33", 133));
        Assert.assertThat(tracker.findAll().length, is(4));
    }
    /** Test 1 of many.  */
    @Test
    public void testDelete() {
        Tracker tracker = new Tracker();
        Item item = tracker.add(new Item("name01", "desc01", 101));
        item = tracker.add(new Item("name02", "desc02", 102));
        item = tracker.add(new Item("name03", "desc03", 103));
        item = tracker.add(new Item("name03", "desc33", 133));
        tracker.delete(tracker.findByName("name01")[0]);
        tracker.delete(tracker.findByName("name02")[0]);
        Assert.assertThat(tracker.findAll().length, is(2));
    }
    /** Test 1 of many.  */
    @Test
    public void testFindByName() {
        Tracker tracker = new Tracker();
        Item item = tracker.add(new Item("name01", "desc01", 101));
        item = tracker.add(new Item("name02", "desc02", 102));
        item = tracker.add(new Item("name03", "desc03", 103));
        item = tracker.add(new Item("name03", "desc33", 133));
        Assert.assertThat(tracker.findByName("name03").length, is(2));
    }
    /** Test 1 of many.  */
    @Test
    public void testUpdate() {
        Tracker tracker = new Tracker();
        Item item = tracker.add(new Item("name01", "desc01", 101));
        String tempId = item.getId();
        Item itemChanger = new  Item("name55", "desc55", 155);
        itemChanger.setId(tempId);
        tracker.update(itemChanger);
        Assert.assertThat(itemChanger.getId(), is(tracker.findById(tempId).getId()));
        Assert.assertThat(itemChanger.getName(), is(tracker.findById(tempId).getName()));
        Assert.assertThat(itemChanger.getDescription(), is(tracker.findById(tempId).getDescription()));
        Assert.assertThat(itemChanger.getCreate(), is(tracker.findById(tempId).getCreate()));
    }
    /** Test 1 of many.  */
    @Test
    public void testStubInput() {
        Tracker tracker = new Tracker();
		new StartUI(tracker, new StubInput(new String[] {"0", "n1", "d1", "1", "6"})).init();
			Assert.assertThat(tracker.findAll()[0].getName(), is("n1"));
    }
}
@@ -3085,36 +3085,33 @@
   /** Test 1 of 
-many
+3
 .  */%0A    @Test%0A
@@ -3273,16 +3273,16 @@
 init();%0A
-
 %09%09%09Asser
@@ -3343,9 +3343,868 @@
 ;%0A    %7D%0A
+    /** Test 2 of 3.  */%0A    @Test%0A    public void testStubInputUpdate() %7B%0A        Tracker tracker = new Tracker();%0A%09%09new StartUI(tracker, new StubInput(new String%5B%5D %7B%220%22, %22n1%22, %22d1%22, %220%22, %22n2%22, %22d2%22, %226%22%7D)).init();%0A%09%09String tempId = tracker.findByName(%22n1%22)%5B0%5D.getId();%0A%09%09new StartUI(tracker, new StubInput(new String%5B%5D %7B%222%22, tempId, %22n55%22, %22d55%22, %226%22%7D)).init();%0A%09%09Assert.assertThat(tracker.findByName(%22n55%22)%5B0%5D.getDescription(), is(%22d55%22));%0A    %7D%0A    /** Test 3 of 3.  */%0A    @Test%0A    public void testStubInputDelete() %7B%0A        Tracker tracker = new Tracker();%0A%09%09new StartUI(tracker, new StubInput(new String%5B%5D %7B%220%22, %22n1%22, %22d1%22, %220%22, %22n2%22, %22d2%22, %226%22%7D)).init();%0A%09%09String tempId = tracker.findByName(%22n1%22)%5B0%5D.getId();%0A%09%09new StartUI(tracker, new StubInput(new String%5B%5D %7B%223%22, tempId, %226%22%7D)).init();%0A%09%09Assert.assertThat(tracker.findAll().length, is(1));%0A    %7D%0A
 %7D

add 2 tests