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 (delite).
	*/
	
//	@Test
//	public void whenDeliteThenItemEqualsNull(){
//		Tracker tracker = new Tracker();
//		Item item = new Item("second", "description2", 2);
//		tracker.delite(item);
//		assertThat( is(null));
//		
//	}

	/*
	* 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);
	}
	
}
@@ -1205,17 +1205,17 @@
 ove (del
-i
+e
 te).%0A%09*/
@@ -1221,19 +1221,15 @@
 /%0A%09%0A
-//
 %09@Test%0A
-//
 %09pub
@@ -1244,17 +1244,17 @@
  whenDel
-i
+e
 teThenIt
@@ -1269,18 +1269,16 @@
 Null()%7B%0A
-//
 %09%09Tracke
@@ -1304,18 +1304,16 @@
 cker();%0A
-//
 %09%09Item i
@@ -1357,18 +1357,16 @@
 2%22, 2);%0A
-//
 %09%09tracke
@@ -1370,17 +1370,17 @@
 cker.del
-i
+e
 te(item)
@@ -1385,42 +1385,88 @@
 m);%0A
-//%09%09assertThat( is(null
+%09%09boolean expected = true;%0A%09%09assertThat(tracker.getAllNull(), is(expected
 ));%0A
-//
 %09%09%0A
-//
 %09%7D%0A%0A
@@ -1497,16 +1497,18 @@
 %09*/%0A%09%09%0A%09
+/*
 @Test%0A%09p
@@ -1916,12 +1916,14 @@
 em1);%0A%09%7D
+*/
 %0A%09%0A%7D

Test class Tracker