Skip to content

Commit 96ddf17

Browse files
Add AppInfoTests
1 parent c09b56a commit 96ddf17

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

  • android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2019 Livio, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* Neither the name of the Livio Inc. nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package com.smartdevicelink.test.rpc.datatypes;
34+
35+
import com.smartdevicelink.proxy.rpc.AppInfo;
36+
import com.smartdevicelink.test.JsonUtils;
37+
import com.smartdevicelink.test.Test;
38+
39+
import junit.framework.TestCase;
40+
41+
import org.json.JSONException;
42+
import org.json.JSONObject;
43+
44+
import java.util.Iterator;
45+
46+
/**
47+
* This is a unit test class for the SmartDeviceLink library project class :
48+
* {@link com.smartdevicelink.proxy.rpc.AppInfo}
49+
*/
50+
public class AppInfoTests extends TestCase {
51+
52+
private AppInfo msg;
53+
54+
@Override
55+
public void setUp() {
56+
57+
msg = new AppInfo();
58+
msg.setAppDisplayName(Test.GENERAL_STRING);
59+
msg.setAppBundleID(Test.GENERAL_STRING);
60+
msg.setAppVersion(Test.GENERAL_STRING);
61+
msg.setAppIcon(Test.GENERAL_STRING);
62+
}
63+
64+
/**
65+
* Tests the expected values of the RPC message.
66+
*/
67+
public void testRpcValues () {
68+
// Test Values
69+
String appDisplayName = msg.getAppDisplayName();
70+
String appBundleID = msg.getAppBundleID();
71+
String appVersion = msg.getAppVersion();
72+
String appIcon = msg.getAppIcon();
73+
74+
// Valid Tests
75+
assertEquals(Test.GENERAL_STRING, appDisplayName);
76+
assertEquals(Test.GENERAL_STRING, appBundleID);
77+
assertEquals(Test.GENERAL_STRING, appVersion);
78+
assertEquals(Test.GENERAL_STRING, appIcon);
79+
80+
// Invalid/Null Tests
81+
AppInfo msg = new AppInfo();
82+
assertNotNull(Test.NOT_NULL, msg);
83+
84+
assertNull(Test.NULL, msg.getAppDisplayName());
85+
assertNull(Test.NULL, msg.getAppBundleID());
86+
assertNull(Test.NULL, msg.getAppVersion());
87+
assertNull(Test.NULL, msg.getAppIcon());
88+
}
89+
90+
public void testJson(){
91+
JSONObject reference = new JSONObject();
92+
93+
try{
94+
reference.put(AppInfo.KEY_APP_DISPLAY_NAME, Test.GENERAL_STRING);
95+
reference.put(AppInfo.KEY_APP_BUNDLE_ID, Test.GENERAL_STRING);
96+
reference.put(AppInfo.KEY_APP_VERSION, Test.GENERAL_STRING);
97+
reference.put(AppInfo.KEY_APP_ICON, Test.GENERAL_STRING);
98+
99+
JSONObject underTest = msg.serializeJSON();
100+
assertEquals(Test.MATCH, reference.length(), underTest.length());
101+
102+
Iterator<?> iterator = reference.keys();
103+
while(iterator.hasNext()){
104+
String key = (String) iterator.next();
105+
assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
106+
}
107+
} catch(JSONException e){
108+
fail(Test.JSON_FAIL);
109+
}
110+
}
111+
112+
}

0 commit comments

Comments
 (0)