blob: f5e36d4dbd2832ac97166f5d5fe6ffc13bedb61c (
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
|
/******************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - 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.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import org.eclipse.egit.github.core.Blob;
import org.eclipse.egit.github.core.client.GsonUtils;
import org.junit.Test;
/**
* Unit tests of {@link GsonUtils}
*/
public class GsonUtilsTest {
/**
* Get Gson instances
*/
@Test
public void getGson() {
assertNotNull(GsonUtils.getGson());
assertNotNull(GsonUtils.getGson(true));
assertNotNull(GsonUtils.getGson(false));
assertNotSame(GsonUtils.getGson(true), GsonUtils.getGson(false));
}
/**
* Create Gson instances
*/
@Test
public void createGson() {
assertNotNull(GsonUtils.createGson());
assertNotNull(GsonUtils.createGson(true));
assertNotNull(GsonUtils.createGson(false));
assertNotSame(GsonUtils.createGson(true), GsonUtils.createGson(false));
}
/**
* Serialize objects with all null fields
*/
@Test
public void noSeriazlizeNulls() {
Blob blob = new Blob();
String json = GsonUtils.toJson(blob, false);
assertEquals("{}", json);
}
/**
* Serialize objects with all null fields
*/
@Test
public void seriazlizeNulls() {
Blob blob = new Blob();
String json = GsonUtils.toJson(blob, true);
assertNotNull(json);
assertTrue(json.length() > 2);
assertFalse("{}".equals(json));
}
}
|