Skip to main content
summaryrefslogtreecommitdiffstats
blob: 64074601237d3723913ea7ec7ed7fcd53fc4a427 (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
/*******************************************************************************
 * Copyright (c) 2012 Tasktop Technologies and others.
 * 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.gerrit.core.client;

import static org.junit.Assert.assertEquals;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import org.junit.Test;

/**
 * @author Steffen Pingel
 */
public class JSonSupportTest {

	@Test
	public void testParseDate() {
		JSonSupport json = new JSonSupport();
		Calendar c = new GregorianCalendar(2012, 0, 26, 12, 33, 11);
		c.set(Calendar.MILLISECOND, 110);
		c.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
		assertEquals(new Timestamp(c.getTimeInMillis()),
				json.parseResponse("\"2012-01-26 12:33:11.110000000\"", Timestamp.class)); //$NON-NLS-1$

		c = new GregorianCalendar(2012, 10, 8, 21, 38, 35);
		c.set(Calendar.MILLISECOND, 337);
		c.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
		assertEquals(new Timestamp(c.getTimeInMillis()),
				json.parseResponse("\"2012-11-08 21:38:35.337000000\"", Timestamp.class)); //$NON-NLS-1$
	}

	@Test(expected = IllegalArgumentException.class)
	public void testParseResponseNull() {
		new JSonSupport().parseResponse(null, Timestamp.class);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testParseResponseEmpty() {
		new JSonSupport().parseResponse("", Timestamp.class); //$NON-NLS-1$
	}
}

Back to the top