package ru.job4j.Tracker;


import org.junit.Test;

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

/**
 * Created by Comp on 22.06.2017.
 */
public class StubInputTest {
    @Test
    public void whenUserAddItemThenTrackerHasNewItemWithSameName() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key001", "1", "test name1", "desc1", "6"});
        new StartUI(input, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name1"));
    }

    @Test
    public void whenShowAllItemsThenTrackerHasShowItemWithSameName() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key001", "1", "test name1", "desc1", "6"});
        Input input1 = new StubInput(new String[]{"1", "key001", "1", "test name1", "desc1", "6"});
        new StartUI(input, tracker).init();
        new StartUI(input1, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name1"));
    }
    @Test
    public void whenUserFindByIdItemThenTrackerHasItemWithName() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key002", "2", "test name2", "desc2", "6"});
        Input input1 = new StubInput(new String[]{"4", "key002", "2", "test name2", "desc2", "6"});
        new StartUI(input, tracker).init();
        new StartUI(input1, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name2"));
    }

    @Test
    public void whenUserDeleteItemThenTrackerHasNullItem() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key002", "2", "test name2", "desc2", "6"});
        Input input2 = new StubInput(new String[]{"0", "key003", "3", "test name3", "desc3", "6"});
        Input input1 = new StubInput(new String[]{"3", "key003", "3", "test name3", "desc3", "6"});
        new StartUI(input, tracker).init();
        new StartUI(input2, tracker).init();
        new StartUI(input1, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name2"));
    }

    @Test
    public void whenUserUpdateItemThenTrackerHasAnotherItem() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key004", "4", "test name4", "desc4", "6"});
        Input input1 = new StubInput(new String[]{"0", "key006", "6", "test name6", "desc6", "6"});
        Input input2 = new StubInput(new String[]{"2", "key006", "6", "test name6", "desc6", "6"});
        new StartUI(input, tracker).init();
        new StartUI(input1, tracker).init();
        new StartUI(input2, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name6"));
    }

    @Test
    public void whenUserFindByNameItemThenTrackerHasItemWithName() {
        Tracker tracker = new Tracker();//key, id, name, desc, creat
        Input input = new StubInput(new String[]{"0", "key005", "5", "test name5", "desc5", "6"});
        Input input1 = new StubInput(new String[]{"5", "key005", "5", "test name5", "desc5", "6"});
        new StartUI(input, tracker).init();
        new StartUI(input1, tracker).init();
        assertThat(tracker.findAll()[0].getName(), is("test name5"));
    }
}

@@ -859,62 +859,10 @@
  %226%22
-%7D);%0A        Input input1 = new StubInput(new String%5B%5D%7B
+, 
 %221%22,
@@ -955,53 +955,8 @@
 ();%0A
-        new StartUI(input1, tracker).init();%0A
     
@@ -1272,62 +1272,10 @@
  %226%22
-%7D);%0A        Input input1 = new StubInput(new String%5B%5D%7B
+, 
 %224%22,
@@ -1368,53 +1368,8 @@
 ();%0A
-        new StartUI(input1, tracker).init();%0A
     
@@ -1680,327 +1680,133 @@
  %226%22
-%7D);%0A        Input input2 = new StubInput(new String%5B%5D%7B%220%22, %22key003%22, %223%22, %22test name3%22, %22desc3%22, %226%22%7D);%0A        Input input1 = new StubInput(new String%5B%5D%7B%223%22, %22key003%22, %223%22, %22test name3%22, %22desc3%22, %226%22%7D);%0A        new StartUI(input, tracker).init();%0A        new StartUI(input2, tracker).init();%0A        new StartUI(input1
+, %220%22, %22key003%22, %223%22, %22test name3%22, %22desc3%22, %226%22, %223%22, %22key003%22, %223%22, %22test name3%22, %22desc3%22, %226%22%7D);%0A        new StartUI(input
 , tr
@@ -2139,162 +2139,10 @@
  %226%22
-%7D);%0A        Input input1 = new StubInput(new String%5B%5D%7B%220%22, %22key006%22, %226%22, %22test name6%22, %22desc6%22, %226%22%7D);%0A        Input input2 = new StubInput(new String%5B%5D%7B
+, 
 %222%22,
@@ -2235,98 +2235,8 @@
 ();%0A
-        new StartUI(input1, tracker).init();%0A        new StartUI(input2, tracker).init();%0A
     
@@ -2555,62 +2555,10 @@
  %226%22
-%7D);%0A        Input input1 = new StubInput(new String%5B%5D%7B
+, 
 %225%22,
@@ -2651,53 +2651,8 @@
 ();%0A
-        new StartUI(input1, tracker).init();%0A
     

add new change in task StubInputTest