package ru.job4j.start;

import org.junit.Test;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;

import java.util.Date;
import ru.job4j.models.Item;
import ru.job4j.start.*;

/**.
* chapter_002
* It's class for testing behavior users
* 
* @author Anton Vasilyuk
* @version 1.0
* @since 0.1
*/

public class StubInputTest {

	/**.
	* @date date for getTime
	*/
	private Date date = new Date();

	/**.
	* Test for method ADD
	*/
	@Test
	public void whenUserAddItemThenTrackerHasNewItemWithSameName() {
		Tracker tracker = new Tracker();
		Input input = new StubInput(new String[] {"0", "Testing name", "desc", "6"});
		new StartUI(input, tracker).init();
		assertThat(tracker.findAll()[0].getName(), is("test name"));
	}

	/**.
	* Test for method FINDALL
	*/
	@Test
	public void whenUserFindAllItemThenTrackerHasShowAllItemWithSameName() {
		Tracker tracker = new Tracker();
		Item item = new Item("Ivan","desc", date.getTime());
		tracker.add(item);
		Input input = new StubInput(new String[] {"1", "6"});
		new StartUI(input, tracker).init();
		assertThat(tracker.findAll()[0].getName(), is("Ivan"));
	}

	/**.
	* Test for method EDIT
	*/
	@Test
	public void whenUserEditItemThenTrackerHasEditItemById() {
		Tracker tracker = new Tracker();
		Item item = new Item("Ivan","desc", date.getTime());
		tracker.add(item);
		item.setId("1");
		Input input = new StubInput(new String[] {"2", "1", "Egor", "desc", "6"});
		new StartUI(input, tracker).init();
		assertThat(tracker.findAll()[0].getName(), is("Egor"));
	}

	/**.
	* Test for method DELETE
	*/
	@Test
	public void whenUserDeleteItemThenTrackerHasDeleteItemById() {
		Tracker tracker = new Tracker();
		Item item = new Item("Ivan","desc", date.getTime());
		tracker.add(item);
		item.setId("1");
		Input input = new StubInput(new String[] {"3", "1", "6"});
		new StartUI(input, tracker).init();
		assertNull(tracker.findAll()[0]);
	}

	/**.
	* Test for method FIND BY ID
	*/
	@Test
	public void whenUserFindByIdItemThenTrackerHasFindItemById() {
		Tracker tracker = new Tracker();
		Item item = new Item("Ivan","desc", date.getTime());
		tracker.add(item);
		item.setId("1");
		Input input = new StubInput(new String[] {"4", "1", "6"});
		new StartUI(input, tracker).init();
		assertThat(tracker.findAll()[0].getName(), is("Ivan"));
	}

	/**.
	* Test for method FIND BY NAME
	*/
	@Test
	public void whenUserFindByNameItemThenTrackerHasFindItemByName() {
		Tracker tracker = new Tracker();
		Item item = new Item("Zoiberg","Bingo", date.getTime());
		tracker.add(item);
		Input input = new StubInput(new String[] {"5", "Zoiberg", "6"});
		new StartUI(input, tracker).init();
		assertThat(tracker.findAll()[0].getDesc(), is("Bingo"));
	}
}
@@ -774,20 +774,23 @@
 (), is(%22
-t
+T
 est
+ing
  name%22))
@@ -1804,38 +1804,51 @@
 dd(item);%0A%09%09
+String itemId = 
 item.
-s
+g
 etId(
-%221%22
 );%0A%09%09Input i
@@ -1887,19 +1887,22 @@
 %5D %7B%223%22, 
-%221%22
+itemId
 , %226%22%7D);
@@ -1965,24 +1965,28 @@
 ker.find
-All()%5B0%5D
+ById(itemId)
 );%0A%09%7D%0A%0A%09

add file for chapter_002_2.5.3