Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5e1a81cece7bb321c2f1252da1f36e142b233b60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*******************************************************************************
 *  Copyright (c) 2011 Christian Trutz
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *    Christian Trutz - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Date;

import org.eclipse.egit.github.core.Comment;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
 * Unit tests of {@link Comment}
 */
public class CommentTest {

	/**
	 * Test default state of comment
	 */
	@Test
	public void defaultState() {
		Comment comment = new Comment();
		assertNull(comment.getBody());
		assertNull(comment.getBodyHtml());
		assertNull(comment.getBodyText());
		assertNull(comment.getCreatedAt());
		assertEquals(0, comment.getId());
		assertNull(comment.getUpdatedAt());
		assertNull(comment.getUrl());
		assertNull(comment.getUser());
	}

	/**
	 * Test updating comment fields
	 */
	@Test
	public void updateFields() {
		Comment comment = new Comment();
		assertEquals("body", comment.setBody("body").getBody());
		assertEquals("<body>", comment.setBodyHtml("<body>").getBodyHtml());
		assertEquals("text", comment.setBodyText("text").getBodyText());
		assertEquals(new Date(1234), comment.setCreatedAt(new Date(1234))
				.getCreatedAt());
		assertEquals(100, comment.setId(100).getId());
		assertEquals(new Date(2345), comment.setUpdatedAt(new Date(2345))
				.getUpdatedAt());
		assertEquals("http", comment.setUrl("http").getUrl());
		User user = new User().setLogin("auser");
		assertEquals(user, comment.setUser(user).getUser());
	}

	/**
	 * Test non-mutable created at date
	 */
	@Test
	public void getCreatedAtReferenceMutableObject() {
		Comment comment = new Comment();
		comment.setCreatedAt(new Date(12345));
		comment.getCreatedAt().setTime(0);
		assertTrue(comment.getCreatedAt().getTime() != 0);
	}

	/**
	 * Test non-mutable updated at date
	 */
	@Test
	public void getUpdatedAtReferenceMutableObject() {
		Comment comment = new Comment();
		comment.setUpdatedAt(new Date(54321));
		comment.getUpdatedAt().setTime(0);
		assertTrue(comment.getUpdatedAt().getTime() != 0);
	}
}

Back to the top