summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatMemoryActionTest.java
blob: c949c921605d5489c8f8b679f1e8644f08f6d78b (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
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.proxy.rpc.SeatMemoryAction;
import com.smartdevicelink.proxy.rpc.enums.SeatMemoryActionType;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;

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.proxy.rpc.SeatMemoryAction}
 */
public class SeatMemoryActionTest extends TestCase {

    private SeatMemoryAction msg;

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

        msg.setId(TestValues.GENERAL_INT);
        msg.setLabel(TestValues.GENERAL_STRING);
        msg.setAction(TestValues.GENERAL_SEATMEMORYACTIONTYPE);
    }

    /**
     * Tests the expected values of the RPC message.
     */
    public void testRpcValues() {
        // Test Values
        Integer id = msg.getId();
        String label = msg.getLabel();
        SeatMemoryActionType action = msg.getAction();

        // Valid Tests
        assertEquals(TestValues.MATCH, (Integer) TestValues.GENERAL_INT, id);
        assertEquals(TestValues.MATCH, TestValues.GENERAL_STRING, label);
        assertEquals(TestValues.MATCH, TestValues.GENERAL_SEATMEMORYACTIONTYPE, action);

        // Invalid/Null Tests
        SeatMemoryAction msg = new SeatMemoryAction();
        assertNotNull(TestValues.NOT_NULL, msg);

        assertNull(TestValues.NULL, msg.getId());
        assertNull(TestValues.NULL, msg.getLabel());
        assertNull(TestValues.NULL, msg.getAction());
    }

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

        try {
            reference.put(SeatMemoryAction.KEY_ID, TestValues.GENERAL_INT);
            reference.put(SeatMemoryAction.KEY_LABEL, TestValues.GENERAL_STRING);
            reference.put(SeatMemoryAction.KEY_ACTION, TestValues.GENERAL_SEATMEMORYACTIONTYPE);

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

            Iterator<?> iterator = reference.keys();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
            }
        } catch (JSONException e) {
            fail(TestValues.JSON_FAIL);
        }
    }
}