Skip to content

Commit d0a7625

Browse files
Merge branch 'develop' into feature/issue_1605_menu_manager_refactor
2 parents 7b02f59 + 732801d commit d0a7625

27 files changed

Lines changed: 1153 additions & 172 deletions

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/video/HapticInterfaceManagerTest.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
**************************************************************************************************/
2222
package com.smartdevicelink.managers.video;
2323

24+
import android.content.Context;
2425
import android.view.View;
2526
import android.view.ViewGroup;
2627
import android.widget.Button;
@@ -45,9 +46,7 @@
4546
import org.mockito.ArgumentCaptor;
4647
import org.mockito.Captor;
4748
import org.mockito.Mock;
48-
import org.mockito.invocation.InvocationOnMock;
4949
import org.mockito.junit.MockitoJUnitRunner;
50-
import org.mockito.stubbing.Answer;
5150

5251
import java.util.ArrayList;
5352
import java.util.List;
@@ -56,7 +55,6 @@
5655
import static org.mockito.ArgumentMatchers.eq;
5756
import static org.mockito.ArgumentMatchers.isNull;
5857
import static org.mockito.Mockito.any;
59-
import static org.mockito.Mockito.doAnswer;
6058
import static org.mockito.Mockito.doReturn;
6159
import static org.mockito.Mockito.mock;
6260
import static org.mockito.Mockito.times;
@@ -222,36 +220,53 @@ public void testRefreshWithUserData() throws Exception {
222220
}
223221

224222
private View createViews() {
223+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
225224

226-
View view = mock(View.class);
225+
final View view = new View(context) {
226+
private int count = 0;
227227

228-
ViewGroup parent1 = mock(ViewGroup.class);
229-
ViewGroup parent2 = mock(ViewGroup.class);
228+
@Override
229+
public boolean isClickable() {
230+
int curCount = count++;
231+
return (curCount >= 1) && (curCount <= 4);
232+
}
233+
};
230234

231-
when(parent1.getChildCount()).thenReturn(5);
235+
final ViewGroup parent1 = new ViewGroup(context) {
236+
@Override
237+
protected void onLayout(boolean b, int i, int i1, int i2, int i3) {}
232238

233-
when(parent1.getChildAt(0)).thenReturn(view);
234-
when(parent1.getChildAt(1)).thenReturn(view);
235-
when(parent1.getChildAt(2)).thenReturn(view);
236-
when(parent1.getChildAt(3)).thenReturn(parent2);
237-
when(parent1.getChildAt(4)).thenReturn(view);
239+
@Override
240+
public View getChildAt(int index) {
241+
return view;
242+
}
238243

239-
when(parent2.getChildCount()).thenReturn(2);
240-
when(parent2.getChildAt(0)).thenReturn(view);
241-
when(parent2.getChildAt(1)).thenReturn(view);
244+
@Override
245+
public int getChildCount() {
246+
return 2;
247+
}
248+
};
242249

250+
final ViewGroup parent2 = new ViewGroup(context) {
251+
@Override
252+
protected void onLayout(boolean b, int i, int i1, int i2, int i3) {}
243253

244-
doAnswer(new Answer<Boolean>() {
245-
private int count = 0;
254+
@Override
255+
public View getChildAt(int index) {
256+
if (index == 3) {
257+
return parent1;
258+
} else {
259+
return view;
260+
}
261+
}
246262

247263
@Override
248-
public Boolean answer(InvocationOnMock invocation) throws Throwable {
249-
int curCount = count++;
250-
return (curCount >= 1) && (curCount <= 4);
264+
public int getChildCount() {
265+
return 5;
251266
}
252-
}).when(view).isClickable();
267+
};
253268

254-
return parent1;
269+
return parent2;
255270
}
256271

257272

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleTypeTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import org.json.JSONException;
1010
import org.json.JSONObject;
11+
import org.junit.Assert;
1112

13+
import java.util.HashMap;
14+
import java.util.Hashtable;
1215
import java.util.Iterator;
1316

1417
public class VehicleTypeTest extends TestCase {
@@ -72,4 +75,15 @@ public void testJson() {
7275
fail(TestValues.JSON_FAIL);
7376
}
7477
}
78+
79+
public void testHashMapConstructor() {
80+
Hashtable<String, Object> store = msg.getStore();
81+
HashMap<String, Object> hashMap = new HashMap(store);
82+
VehicleType type = new VehicleType(hashMap);
83+
84+
Assert.assertEquals(type.getMake(), msg.getMake());
85+
Assert.assertEquals(type.getModel(), msg.getModel());
86+
Assert.assertEquals(type.getModelYear(), msg.getModelYear());
87+
Assert.assertEquals(type.getTrim(), msg.getTrim());
88+
}
7589
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/util/SdlAppInfoTests.java

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@
4242
import androidx.test.ext.junit.runners.AndroidJUnit4;
4343

4444
import com.smartdevicelink.R;
45+
import com.smartdevicelink.proxy.rpc.VehicleType;
46+
import com.smartdevicelink.test.TestValues;
4547
import com.smartdevicelink.util.SdlAppInfo;
4648

4749
import org.junit.Before;
4850
import org.junit.Test;
4951
import org.junit.runner.RunWith;
5052

5153
import java.util.ArrayList;
54+
import java.util.Arrays;
5255
import java.util.Collections;
5356
import java.util.List;
5457

5558
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
59+
import static junit.framework.Assert.assertTrue;
5660
import static junit.framework.TestCase.assertEquals;
5761
import static junit.framework.TestCase.assertFalse;
5862
import static junit.framework.TestCase.assertNotNull;
@@ -85,7 +89,7 @@ public void setUp() throws Exception {
8589
@Test
8690
public void testConstructorWithDefaultData() {
8791

88-
SdlAppInfo info = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
92+
SdlAppInfo info = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
8993

9094
assertNotNull(info);
9195

@@ -105,10 +109,10 @@ public void testConstructorWithDefaultData() {
105109
*/
106110
@Test
107111
public void testCompareVersion() {
108-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
112+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
109113

110114
int newVersion = context.getResources().getInteger(R.integer.sdl_router_service_version_value) + 1;
111-
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", false), defaultPackageInfo);
115+
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", false), defaultPackageInfo, context);
112116

113117
List<SdlAppInfo> infos = new ArrayList<>();
114118
infos.add(defaultInfo);
@@ -126,10 +130,10 @@ public void testCompareVersion() {
126130
*/
127131
@Test
128132
public void testCompareVersionAndCustom() {
129-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
133+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
130134

131135
int newVersion = context.getResources().getInteger(R.integer.sdl_router_service_version_value) + 1;
132-
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", true), defaultPackageInfo);
136+
SdlAppInfo testInfo = new SdlAppInfo(createResolveInfo(newVersion, "com.smartdevicelink.test2", "com.smartdevicelink.test2.SdlRouterService", true), defaultPackageInfo, context);
133137

134138
List<SdlAppInfo> infos = new ArrayList<>();
135139
infos.add(defaultInfo);
@@ -147,12 +151,12 @@ public void testCompareVersionAndCustom() {
147151
*/
148152
@Test
149153
public void testCompareUpdatedTime() {
150-
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo);
154+
SdlAppInfo defaultInfo = new SdlAppInfo(defaultResolveInfo, defaultPackageInfo, context);
151155

152156
PackageInfo packageInfo = new PackageInfo();
153157
packageInfo.firstInstallTime = defaultPackageInfo.firstInstallTime;
154158
packageInfo.lastUpdateTime = defaultPackageInfo.lastUpdateTime + 500;
155-
SdlAppInfo testInfo = new SdlAppInfo(defaultResolveInfo, packageInfo);
159+
SdlAppInfo testInfo = new SdlAppInfo(defaultResolveInfo, packageInfo, context);
156160

157161
List<SdlAppInfo> infos = new ArrayList<>();
158162
infos.add(defaultInfo);
@@ -179,5 +183,106 @@ public ResolveInfo createResolveInfo(int routerServiceVersion, String packageNam
179183
return info;
180184
}
181185

186+
@Test
187+
public void testDeserializeVehicleInfo() {
188+
VehicleType type = new VehicleType();
189+
type.setMake("SDL");
190+
type.setModel("Car");
191+
type.setModelYear("2019");
192+
type.setTrim("GT");
193+
List<VehicleType> deserializedList = SdlAppInfo.deserializeSupportedVehicles(getInstrumentation().getContext().getResources().getXml(com.smartdevicelink.test.R.xml.supported_vehicle_type));
194+
assertTrue(deserializedList.contains(type));
195+
assertEquals(1, deserializedList.size());
196+
}
197+
198+
@Test
199+
public void testVehicleTypeSupported() {
200+
// tests check with all params
201+
VehicleType type1 = new VehicleType();
202+
type1.setMake(TestValues.GENERAL_STRING);
203+
type1.setModel(TestValues.GENERAL_STRING);
204+
type1.setMake(TestValues.GENERAL_STRING);
205+
type1.setTrim(TestValues.GENERAL_STRING);
206+
207+
VehicleType type2 = new VehicleType();
208+
type2.setMake(TestValues.GENERAL_STRING);
209+
type2.setModel(TestValues.GENERAL_STRING);
210+
type2.setModelYear(TestValues.GENERAL_INTEGER.toString());
211+
type2.setTrim(TestValues.GENERAL_STRING);
212+
213+
List<VehicleType> supportedVehicleList = Arrays.asList(type1, type2);
214+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, type2));
215+
216+
// tests check with not all params in connectedVehicle
217+
VehicleType connectedVehicle = new VehicleType();
218+
219+
// make only param
220+
connectedVehicle.setMake(TestValues.GENERAL_STRING);
221+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
222+
223+
// make and model params
224+
connectedVehicle.setModel(TestValues.GENERAL_STRING);
225+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
226+
227+
// make, model and year params
228+
connectedVehicle.setModelYear(TestValues.GENERAL_STRING);
229+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
230+
231+
// make, model and trim params
232+
connectedVehicle.setModelYear(null);
233+
connectedVehicle.setTrim(TestValues.GENERAL_STRING);
234+
assertTrue(SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, connectedVehicle));
235+
236+
// tests check with not all params in supportedVehicle
237+
VehicleType supportedVehicle = new VehicleType();
238+
supportedVehicle.setMake(TestValues.GENERAL_STRING);
239+
240+
// make param only
241+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
242+
243+
// make and model params
244+
supportedVehicle.setModel(TestValues.GENERAL_STRING);
245+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
246+
247+
// make, model and trim params
248+
supportedVehicle.setTrim(TestValues.GENERAL_STRING);
249+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
250+
251+
// make, model and trim params
252+
supportedVehicle.setTrim(TestValues.GENERAL_STRING);
253+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
254+
255+
// make, model and trim params
256+
connectedVehicle.setTrim(null);
257+
connectedVehicle.setModelYear(TestValues.GENERAL_INTEGER.toString());
258+
supportedVehicle.setModelYear(TestValues.GENERAL_INTEGER.toString());
259+
assertTrue(SdlAppInfo.checkIfVehicleSupported(Collections.singletonList(supportedVehicle), connectedVehicle));
260+
}
261+
262+
@Test
263+
public void testVehicleTypeNotSupported() {
264+
VehicleType type1 = new VehicleType();
265+
266+
type1.setModel(TestValues.GENERAL_STRING);
267+
type1.setMake(TestValues.GENERAL_INTEGER.toString());
268+
type1.setTrim(TestValues.GENERAL_STRING);
269+
type1.setModelYear(TestValues.GENERAL_STRING);
270+
271+
VehicleType type2 = new VehicleType();
272+
273+
type2.setModel(TestValues.GENERAL_STRING);
274+
type2.setMake(TestValues.GENERAL_INTEGER.toString());
275+
type2.setTrim(TestValues.GENERAL_STRING);
276+
type2.setModelYear(TestValues.GENERAL_STRING);
277+
278+
VehicleType type3 = new VehicleType();
279+
280+
type3.setModel(TestValues.GENERAL_STRING);
281+
type3.setMake(TestValues.GENERAL_STRING);
282+
type3.setTrim(TestValues.GENERAL_STRING);
283+
type3.setModelYear(TestValues.GENERAL_INTEGER.toString());
284+
285+
assertFalse(SdlAppInfo.checkIfVehicleSupported(Arrays.asList(type1, type2), type3));
286+
}
182287

183288
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/utl/AndroidToolsTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package com.smartdevicelink.test.utl;
22

33
import android.content.ComponentName;
4+
import android.content.Context;
5+
import android.content.SharedPreferences;
46

57
import androidx.test.ext.junit.runners.AndroidJUnit4;
68

9+
import com.smartdevicelink.proxy.rpc.VehicleType;
710
import com.smartdevicelink.util.AndroidTools;
811

912
import junit.framework.Assert;
1013

14+
import org.json.JSONException;
1115
import org.junit.Test;
1216
import org.junit.runner.RunWith;
17+
import org.mockito.Mockito;
1318

1419
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20+
import static org.mockito.ArgumentMatchers.anyInt;
21+
import static org.mockito.ArgumentMatchers.anyString;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
1524

1625
@RunWith(AndroidJUnit4.class)
1726
public class AndroidToolsTests {
@@ -39,4 +48,32 @@ public void testIsServiceExportedNull() {
3948

4049
}
4150

51+
@Test
52+
public void testVehicleTypeSave() throws JSONException {
53+
Context mMockContext = mock(Context.class);
54+
VehicleType mMockVehicleType = new VehicleType();
55+
String mAddress = "1234";
56+
57+
mMockVehicleType.setMake("Ford");
58+
mMockVehicleType.setTrim("GT");
59+
mMockVehicleType.setModel("Mustang");
60+
mMockVehicleType.setModelYear("2019");
61+
62+
SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
63+
when(editor.commit()).thenReturn(true);
64+
65+
SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
66+
when(mMockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPrefs);
67+
when(sharedPrefs.edit()).thenReturn(editor);
68+
when(sharedPrefs.getString(mAddress, null)).thenReturn(mMockVehicleType.serializeJSON().toString());
69+
70+
AndroidTools.saveVehicleType(mMockContext, mMockVehicleType, mAddress);
71+
VehicleType type = new VehicleType(AndroidTools.getVehicleTypeFromPrefs(mMockContext, mAddress));
72+
73+
org.junit.Assert.assertEquals(type.getMake(), mMockVehicleType.getMake());
74+
org.junit.Assert.assertEquals(type.getModel(), mMockVehicleType.getModel());
75+
org.junit.Assert.assertEquals(type.getModelYear(), mMockVehicleType.getModelYear());
76+
org.junit.Assert.assertEquals(type.getTrim(), mMockVehicleType.getTrim());
77+
}
78+
4279
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resource>
3+
<vehicle-type
4+
make="SDL"
5+
model="Car"
6+
modelYear="2019"
7+
trim="GT" />
8+
9+
<vehicle-type
10+
make="SDL2"
11+
modelYear="2019" />
12+
</resource>

android/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void run() {
337337
Looper.prepare();
338338

339339
// create a Handler for this thread
340-
mHandler = new Handler() {
340+
mHandler = new Handler(Looper.myLooper()) {
341341
public void handleMessage(Message msg) {
342342
switch (msg.what) {
343343
case MSG_TICK: {

0 commit comments

Comments
 (0)