package at.fhj.swd14.pse.comment;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import at.fhj.swd14.pse.message.Message;
import at.fhj.swd14.pse.user.User;

public class CommentTest
{
	private Comment c;
		
	@Before
	public void setup()
	{
		c = new Comment();
	}
	
	@Test
	public void testCommentConstructor()
	{
		Comment c = new Comment();
		Assert.assertTrue(c instanceof Comment);
	}

	@Test
	public void testCommentConstructor2()
	{
		Long id = 1L;
		Comment c = new Comment(id);
		Assert.assertEquals(id, c.getId());
	}

	@Test
	public void testId()
	{
		Long id = 1L;
		c.setId(id);
		Assert.assertEquals(id, c.getId());
	}

	@Test
	public void testText()
	{
		c.setText("blabla");
		Assert.assertEquals("blabla", c.getText());
	}

	@Test
	public void testAuthor()
	{
		Long id = 1L;
		User user = new User(id);
		c.setAuthor(user);
		Assert.assertEquals(user, c.getAuthor());
	}

	@Test
	public void testParentMessage()
	{
		Long id = 1L;
		Message parentMessage = new Message(id);
		c.setParentMessage(parentMessage);
		Assert.assertEquals(parentMessage, c.getParentMessage());
	}

	@Test
	public void testUsers()
	{
		List<User> users = new ArrayList<>();
		Long id1 = 1L;
		User user1 = new User(id1);
		Long id2 = 1L;
		User user2 = new User(id2);
		
		users.add(user1);
		users.add(user2);
		
		c.setUsers(users);
		
		Assert.assertTrue(c.getUsers().containsAll(users));
	}

	@Test
	public void testGetCreated()
	{
		Assert.assertEquals(null, c.getCreated());
	}

	@Test
	public void testGetModified()
	{
		Assert.assertEquals(null, c.getModified());
	}

	@Test
	public void testToString()
	{	
		User author = new User(1L);
		Message parentMessage = new Message(1L);
		
		c.setId(1L);
		c.setAuthor(author);
		c.setParentMessage(parentMessage);

		String s = "Comment{" +
                "id=" + c.getId() +
                ", userId='" + c.getAuthor() + '\'' +
                ", messageId='" + c.getParentMessage().getId() + '\'' +
                '}';
		
		Assert.assertEquals(s, c.toString());
	}

}

@@ -278,18 +278,16 @@
 ment c;%0A
-%09%09
 %0A%09@Befor
@@ -336,17 +336,16 @@
 t();%0A%09%7D%0A
-%09
 %0A%09@Test%0A
@@ -1332,18 +1332,16 @@
 r(id2);%0A
-%09%09
 %0A%09%09users
@@ -1373,18 +1373,16 @@
 user2);%0A
-%09%09
 %0A%09%09c.set
@@ -1395,18 +1395,16 @@
 users);%0A
-%09%09
 %0A%09%09Asser
@@ -1671,17 +1671,16 @@
 ing()%0A%09%7B
-%09
 %0A%09%09User 
@@ -1697,17 +1697,17 @@
 ew User(
-1
+2
 L);%0A%09%09Me
@@ -1740,23 +1740,21 @@
 Message(
-1
+3
 L);%0A
-%09%09
 %0A%09%09c.set
@@ -1825,162 +1825,343 @@
 e);%0A
-%0A%09%09String s = %22Comment%7B%22 +%0A                %22id=%22 + c.getId() +%0A                %22, userId='%22 + c.getAuthor() + '%5C'' +%0A                %22, messageId='%22 + c.g
+%09%09author.setMail(%22office@nerdistan.io%22);%0A%0A%09%09String s = %22Comment%7Bid=1, userId='User%7Bid=2, mail='office@nerdistan.io'%7D', messageId='3'%7D%22;%0A%0A%09%09Assert.assertEquals(s, c.toString());%0A%09%7D%0A%0A%09@Test%0A%09public void testToStringParentNull()%0A%09%7B%0A%09%09User author = new User(2L);%0A%09%09Message parentMessage = null;%0A%0A%09%09c.setId(1L);%0A%09%09c.setAuthor(author);%0A%09%09c.s
 etPa
@@ -2176,50 +2176,163 @@
 age(
-).getId() + '%5C'' +%0A                '%7D';%0A%09%09
+parentMessage);%0A%09%09author.setMail(%22office@nerdistan.io%22);%0A%0A%09%09String s = %22Comment%7Bid=1, userId='User%7Bid=2, mail='office@nerdistan.io'%7D', messageId='null'%7D%22;%0A
 %0A%09%09A

update CommentTest