Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e03248c153972402f6c8377f2dad2d3adb47da11 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
 *  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 v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  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.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.Date;

import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.GistFile;
import org.eclipse.egit.github.core.GistRevision;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

/**
 * Unit tests of {@link Gist}
 */
public class GistTest {

	/**
	 * Test default state of gist
	 */
	@Test
	public void defaultState() {
		Gist gist = new Gist();
		assertEquals(0, gist.getComments());
		assertNull(gist.getCreatedAt());
		assertNull(gist.getDescription());
		assertNull(gist.getFiles());
		assertNull(gist.getGitPullUrl());
		assertNull(gist.getGitPushUrl());
		assertNull(gist.getHistory());
		assertNull(gist.getHtmlUrl());
		assertNull(gist.getId());
		assertNull(gist.getUpdatedAt());
		assertNull(gist.getUrl());
		assertNull(gist.getUser());
		assertNull(gist.getOwner());
		assertFalse(gist.isPublic());
	}

	/**
	 * Test updating gist fields
	 */
	@Test
	public void updateFields() {
		Gist gist = new Gist();
		assertEquals(3, gist.setComments(3).getComments());
		assertEquals(new Date(5000), gist.setCreatedAt(new Date(5000))
				.getCreatedAt());
		assertEquals("desc", gist.setDescription("desc").getDescription());
		assertEquals(Collections.emptyMap(),
				gist.setFiles(Collections.<String, GistFile> emptyMap())
						.getFiles());
		assertEquals("pull", gist.setGitPullUrl("pull").getGitPullUrl());
		assertEquals("push", gist.setGitPushUrl("push").getGitPushUrl());
		assertEquals(Collections.emptyList(),
				gist.setHistory(Collections.<GistRevision> emptyList())
						.getHistory());
		assertEquals("html", gist.setHtmlUrl("html").getHtmlUrl());
		assertEquals("id", gist.setId("id").getId());
		assertEquals(new Date(1000), gist.setUpdatedAt(new Date(1000))
				.getUpdatedAt());
		assertEquals("url", gist.setUrl("url").getUrl());
		User user = new User().setLogin("use");
		assertEquals(user, gist.setUser(user).getUser());
		assertTrue(gist.setPublic(true).isPublic());
	}

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

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

Back to the top