Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 28e2fa7d17411a5d8565a5ea829ae370e28eea3b (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
/*******************************************************************************
 *  Copyright (c) 2011 GitHub Inc.
 *  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:
 *    Jason Tsay (GitHub Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.eclipse.egit.github.core.event.Event.TYPE_FOLLOW;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.eclipse.egit.github.core.client.EventFormatter;
import org.eclipse.egit.github.core.client.GsonUtils;
import org.eclipse.egit.github.core.event.Event;
import org.eclipse.egit.github.core.event.EventPayload;
import org.eclipse.egit.github.core.event.FollowPayload;
import org.junit.Test;

/**
 * Unit tests of {@link EventFormatter}
 */
public class EventFormatterTest {

	/**
	 * Follow event payload returned as {@link FollowPayload}
	 */
	@Test
	public void followPayload() {
		Event event = GsonUtils.fromJson("{\"type\":\"" + TYPE_FOLLOW
				+ "\",\"payload\":{}}", Event.class);
		assertNotNull(event);
		assertNotNull(event.getPayload());
		assertEquals(FollowPayload.class, event.getPayload().getClass());
	}

	/**
	 * Unknown event payload returned as {@link EventPayload}
	 */
	@Test
	public void unknownPayload() {
		Event event = GsonUtils.fromJson(
				"{\"type\":\"NotAnEventType\",\"payload\":{}}", Event.class);
		assertNotNull(event);
		assertNotNull(event.getPayload());
		assertEquals(EventPayload.class, event.getPayload().getClass());
	}

	/**
	 * Event with missing type has payload returned as {@link EventPayload}
	 */
	@Test
	public void missingType() {
		Event event = GsonUtils.fromJson("{\"payload\":{}}", Event.class);
		assertNotNull(event);
		assertNotNull(event.getPayload());
		assertEquals(EventPayload.class, event.getPayload().getClass());
	}

	/**
	 * Missing payload
	 */
	@Test
	public void missingPayload() {
		Event event = GsonUtils.fromJson("{}", Event.class);
		assertNotNull(event);
		assertNull(event.getPayload());
	}
}

Back to the top