summaryrefslogtreecommitdiff
path: root/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightCapabilitiesTests.java
blob: 6122f4305c0aa42370e8c8dbe1f8c168ca1ca418 (plain)
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
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.proxy.rpc.LightCapabilities;
import com.smartdevicelink.proxy.rpc.enums.LightName;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.Test;

import junit.framework.TestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

/**
 * This is a unit test class for the SmartDeviceLink library project class :
 * {@link com.smartdevicelink.rpc.LightCapabilities}
 */
public class LightCapabilitiesTests extends TestCase {

	private LightCapabilities msg;

	@Override
	public void setUp() {
		msg = new LightCapabilities();

		msg.setName(Test.GENERAL_LIGHTNAME);
		msg.setDensityAvailable(Test.GENERAL_BOOLEAN);
		msg.setRGBColorSpaceAvailable(Test.GENERAL_BOOLEAN);
		msg.setStatusAvailable(Test.GENERAL_BOOLEAN);
	}

	/**
	 * Tests the expected values of the RPC message.
	 */
	public void testRpcValues() {
		// Test Values
		LightName name = msg.getName();
		Boolean densityAvailable = msg.getDensityAvailable();
		Boolean rgbColorSpaceAvailable = msg.getRGBColorSpaceAvailable();
		Boolean statusAvailable = msg.getStatusAvailable();

		// Valid Tests
		assertEquals(Test.MATCH, Test.GENERAL_LIGHTNAME, name);
		assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) densityAvailable);
		assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) rgbColorSpaceAvailable);
		assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) statusAvailable);

		// Invalid/Null Tests
		LightCapabilities msg = new LightCapabilities();
		assertNotNull(Test.NOT_NULL, msg);

		assertNull(Test.NULL, msg.getName());
		assertNull(Test.NULL, msg.getDensityAvailable());
		assertNull(Test.NULL, msg.getRGBColorSpaceAvailable());
		assertNull(Test.NULL, msg.getStatusAvailable());
	}

	public void testJson() {
		JSONObject reference = new JSONObject();

		try {
			reference.put(LightCapabilities.KEY_NAME, Test.GENERAL_LIGHTNAME);
			reference.put(LightCapabilities.KEY_DENSITY_AVAILABLE, Test.GENERAL_BOOLEAN);
			reference.put(LightCapabilities.KEY_RGB_COLOR_SPACE_AVAILABLE, Test.GENERAL_BOOLEAN);
			reference.put(LightCapabilities.KEY_STATUS_AVAILABLE, Test.GENERAL_BOOLEAN);

			JSONObject underTest = msg.serializeJSON();
			assertEquals(Test.MATCH, reference.length(), underTest.length());

			Iterator<?> iterator = reference.keys();
			while (iterator.hasNext()) {
				String key = (String) iterator.next();

				assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
			}
		} catch (JSONException e) {
			fail(Test.JSON_FAIL);
		}
	}
}