package ru.schernigin.start;

import static org.mockito.Mockito.*;
import ru.schernigin.models.*;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

/**
 * Test class Tracker.
 *
 * @author schernigin.
 * @version 1
 * @since 06.01.2017
 */

public class TrackerTest {

	
	/*
	* Test method add.
	*/

	@Test
	public void whenAddThenNewItem() {
		Tracker tracker = new Tracker();
		Item item = new Item("first", "description", 1);
		tracker.add(item);
		assertThat(item.getName(), is("first"));
		assertThat(item.getDescription(), is("description"));
		assertThat(item.getCreate(), is(1L));
	}
	
	/*
	* Test Generate Id.
	*/
	
	@Test
	public void whenGenerateIdThenNewId() {
		Comparable c = mock(Comparable.class);
		when(c.compareTo("Test")).thenReturn(1);
		assertEquals(1, c.compareTo("Test"));
	}
	
	/*
	* Test method update.
	*/
	
	@Test
	public void whenUpdateThenItemUpdate() {
		Tracker tracker = new Tracker();
		Item item = new Item("second", "description2", 2);
		tracker.update(item);
		assertThat(item.getName(), is("second"));
		assertThat(item.getDescription(), is("description2"));
		assertThat(item.getCreate(), is(2L));
	}
	
	/*
	* Test remove (delete).
	*/
	
	@Test
	public void whenDeleteThenItemEqualsNull(){
		Tracker tracker = new Tracker();
		Item item = new Item("second", "description2", 2);
		tracker.delete(item);
		boolean expected = true;
		assertThat(tracker.getAllNull(), is(expected));
		
	}

	/*
	* Test findByName.
	*/
		
	/*@Test
	public void whenFindByIDTwenReturnItemId() {
		Tracker tracker = new Tracker();
		Item item = new Item("first", "description1", 1);
		Item item1 = new Item("second", "description2", 2);
		Item item2 = new Item("third", "description3", 3);
		Item expected = tracker.findById("second");
		tracker.add(item);
		tracker.add(item1);
		tracker.add(item2);
		tracker.add(expected);
		assertEquals(expected, item1);
	}*/
	
}
@@ -1209,39 +1209,43 @@
 (delete).%0A%09*/%0A%09%0A
+//
 %09@Test%0A
+//
 %09public void whe
@@ -1273,16 +1273,18 @@
 Null()%7B%0A
+//
 %09%09Tracke
@@ -1302,32 +1302,34 @@
  new Tracker();%0A
+//
 %09%09Item item = ne
@@ -1357,34 +1357,47 @@
 cription2%22, 2);%0A
-%09%09
+//%09%09assertNull(
 tracker.delete(i
@@ -1404,83 +1404,15 @@
 tem)
-;%0A%09%09boolean expected = true;%0A%09%09assertThat(tracker.getAllNull(), is(expected
+.getId(
 ));%0A
@@ -1450,18 +1450,16 @@
 %09*/%0A%09%09%0A%09
-/*
 @Test%0A%09p
@@ -1702,24 +1702,84 @@
 ;%0A%09%09
-Item expected = 
+tracker.add(item);%0A%09%09tracker.add(item1);%0A%09%09tracker.add(item2);%0A%09%09assertThat(
 trac
@@ -1788,18 +1788,20 @@
 r.findBy
-Id
+Name
 (%22second
@@ -1802,16 +1802,306 @@
 second%22)
+, is(item1));%0A%09%7D%0A%09%0A%09%0A%09/*%0A%09* Test findById.%0A%09*/%0A%09%0A%09@Test%0A%09public void whenFindByIdThenReturnId() %7B%0A%09%09Tracker tracker = new Tracker();%0A%09%09Item item = new Item(%22first%22, %22description1%22, 1);%0A%09%09Item item1 = new Item(%22second%22, %22description2%22, 2);%0A%09%09Item item2 = new Item(%22third%22, %22description3%22, 3)
 ;%0A%09%09trac
@@ -2165,68 +2165,177 @@
 ;%0A%09%09
-tracker.add(expected);%0A%09%09assertEquals(expected, 
+assertThat(tracker.findById(item2.getId()), is(
 item
-1
+2)
 );%0A%09%7D
-*/%0A%09
+ %0A%09%0A%09/*%0A%09* Test getAll.%0A%09*/%0A%09%0A//%09@Test%0A//%09public void whenGetAllThenReturnAllArrayItems() %7B%0A//%09%09assertThat()%0A//%09%7D
 %0A%7D

Test class Tracker