package ru.job4j.tracker.start;

import org.junit.Test;
import ru.job4j.tracker.models.Item;
import ru.job4j.tracker.controller.Tracker;

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

/**
 * This class tests all method from Tracker.
 *
 * @author Kucykh Vasily (mailto:basil135@mail.ru)
 * @version $Id$
 * @since 12.04.2017
 */
public class TrackerTest {

    /**
     * method tests add element.
     */
    @Test
    public void whenAddOneElementThenThisElementAdd() {

        Item element = new Item("example", null, null);
        Tracker tracker = new Tracker();

        Item expectedItem = element;
        Item actualItem = tracker.add(element);

        assertEquals(expectedItem, actualItem);

    }

    /**
     * method tests changing array items.
     */
    @Test
    public void whenAddTwoElementsThenSizeEqualsTwo() {

        Item elementOne = new Item("name", null, null);
        Item elementTwo = new Item("name", null, null);

        Tracker tracker = new Tracker();

        tracker.add(elementOne);
        tracker.add(elementTwo);

        int expectedValue = 2;
        int actualValue = tracker.size();

        assertThat(actualValue, is(expectedValue));

    }

    /**
     * method tests update and findById.
     */
    @Test
    public void whenUpdateThenFindById() {

        Item elementOne = new Item("name", null, null);
        Item elementTwo = new Item("example", null, null);

        Tracker tracker = new Tracker();

        tracker.add(elementOne);
        elementTwo.setId("1");
        elementOne.setId("1");
        tracker.update(elementTwo);

        Item expectedItem = elementTwo;
        Item actualItem = tracker.findById("1");

        assertEquals(expectedItem, actualItem);

    }

    /**
     * method tests delete and findByName.
     */
    @Test
    public void whenDeleteThenFindByName() {

        Item elementOne = new Item("example", null, null);
        Item elementTwo = new Item("example", null, null);

        Tracker tracker = new Tracker();

        tracker.add(elementOne);
        tracker.add(elementTwo);
        tracker.delete(elementOne);

        Item[] expectedItem = {elementTwo};
        Item[] actualItem = tracker.findByName("example");

        assertThat(actualItem, is(expectedItem));

    }

    /**
     * method tests findAll.
     */
    @Test
    public void whenFindAllThenReturnAll() {

        Item elementOne = new Item("example", null, null);
        Item elementTwo = new Item("example", null, null);

        Tracker tracker = new Tracker();

        tracker.add(elementOne);
        tracker.add(elementTwo);

        Item[] expectedItem = {elementOne, elementTwo};
        Item[] actualItem = tracker.findAll();

        assertThat(actualItem, is(expectedItem));

    }

    /**
     * method tests findByName.
     */
    @Test
    public void whenFindByNameThenReturnAnArray() {

        Item elementOne = new Item("example", null, null);
        Item elementTwo = new Item("example", null, null);
        Item elementThree = new Item("name", null, null);
        Item elementFour = new Item("something", null, null);
        Item elementFive = new Item("just", null, null);
        Item elementSix = new Item("example", null, null);
        Item elementSeven = new Item("lamp", null, null);
        Item elementEight = new Item("name", null, null);
        Item elementNine = new Item("example", null, null);
        Item elementTen = new Item("example", null, null);

        Tracker tracker = new Tracker();

        tracker.add(elementOne);
        tracker.add(elementTwo);
        tracker.add(elementThree);
        tracker.add(elementFour);
        tracker.add(elementFive);
        tracker.add(elementSix);
        tracker.add(elementSeven);
        tracker.add(elementEight);
        tracker.add(elementNine);
        tracker.add(elementTen);

        Item[] expectedItem = {elementOne, elementTwo, elementSix, elementNine, elementTen};
        Item[] actualItem = tracker.findByName("example");

        assertThat(actualItem, is(expectedItem));

    }

}
@@ -77,19 +77,26 @@
 ker.
-models.Item
+controller.Tracker
 ;%0Aim
@@ -117,34 +117,79 @@
 tracker.
-controller.Tracker
+models.Item;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0Aimpor
@@ -2247,38 +2247,42 @@
 tOne);%0A%0A        
+List%3C
 Item
-%5B%5D
+%3E
  expectedItem = 
@@ -2277,25 +2277,68 @@
 ectedItem = 
-%7B
+new ArrayList%3C%3E();%0A        expectedItem.add(
 elementTwo%7D;
@@ -2327,34 +2327,35 @@
 m.add(elementTwo
-%7D;
+);%0A
 %0A        Item%5B%5D 
@@ -2339,38 +2339,42 @@
 tTwo);%0A%0A        
+List%3C
 Item
-%5B%5D
+%3E
  actualItem = tr
@@ -2790,38 +2790,42 @@
 tTwo);%0A%0A        
+List%3C
 Item
-%5B%5D
+%3E
  expectedItem = 
@@ -2820,37 +2820,106 @@
 ectedItem = 
-%7BelementOne, 
+new ArrayList%3C%3E();%0A        expectedItem.add(elementOne);%0A        expectedItem.add(
 elementTwo%7D;
@@ -2916,18 +2916,19 @@
 ementTwo
-%7D;
+);%0A
 %0A       
@@ -2920,38 +2920,42 @@
 tTwo);%0A%0A        
+List%3C
 Item
-%5B%5D
+%3E
  actualItem = tr
@@ -4121,22 +4121,26 @@
         
+List%3C
 Item
-%5B%5D
+%3E
  expecte
@@ -4151,58 +4151,205 @@
 m = 
-%7BelementOne, elementTwo, elementSix, elementNine, 
+new ArrayList%3C%3E();%0A        expectedItem.add(elementOne);%0A        expectedItem.add(elementTwo);%0A        expectedItem.add(elementSix);%0A        expectedItem.add(elementNine);%0A        expectedItem.add(
 elem
@@ -4358,10 +4358,11 @@
 tTen
-%7D;
+);%0A
 %0A   
@@ -4370,14 +4370,18 @@
     
+List%3C
 Item
-%5B%5D
+%3E
  act

Refactor TrackerTest.java replaced array to list