Skip to content

Commit f704580

Browse files
committed
Refactor tests to AndroidJUnit4
1 parent c564973 commit f704580

25 files changed

Lines changed: 424 additions & 221 deletions

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/LockScreenConfigTests.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
package com.smartdevicelink.managers.lockscreen;
22

3-
import com.smartdevicelink.AndroidTestCase2;
3+
import android.support.test.runner.AndroidJUnit4;
4+
45
import com.smartdevicelink.test.TestValues;
56

7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static junit.framework.TestCase.assertEquals;
12+
import static junit.framework.TestCase.assertTrue;
13+
614
/**
715
* This is a unit test class for the SmartDeviceLink library manager class :
816
* {@link com.smartdevicelink.managers.lockscreen.LockScreenConfig}
917
*
1018
* We currently do not need to test null values, as each currently is a primitive
1119
*/
12-
public class LockScreenConfigTests extends AndroidTestCase2 {
20+
@RunWith(AndroidJUnit4.class)
21+
public class LockScreenConfigTests {
1322

1423
private LockScreenConfig lockScreenConfig;
1524

16-
@Override
25+
@Before
1726
public void setUp() throws Exception {
18-
super.setUp();
19-
2027
// set info for all the setters
2128
lockScreenConfig = new LockScreenConfig();
2229
lockScreenConfig.setCustomView(TestValues.GENERAL_INT);
@@ -27,11 +34,7 @@ public void setUp() throws Exception {
2734
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED);
2835
}
2936

30-
@Override
31-
public void tearDown() throws Exception {
32-
super.tearDown();
33-
}
34-
37+
@Test
3538
public void testLockScreenConfig() {
3639

3740
// get the info and make sure its correct

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/LockScreenDeviceIconManagerTests.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,30 @@
33
import android.content.Context;
44
import android.content.SharedPreferences;
55
import android.graphics.Bitmap;
6+
import android.support.test.runner.AndroidJUnit4;
67

7-
import com.smartdevicelink.AndroidTestCase2;
8-
import com.smartdevicelink.util.AndroidTools;
9-
10-
import org.json.JSONException;
11-
import org.json.JSONObject;
8+
import org.junit.Test;
129
import org.junit.rules.TemporaryFolder;
10+
import org.junit.runner.RunWith;
1311
import org.mockito.Mockito;
1412

15-
import java.io.File;
16-
import java.io.IOException;
17-
import java.math.BigInteger;
18-
import java.security.MessageDigest;
19-
import java.security.NoSuchAlgorithmException;
20-
2113
import static org.mockito.ArgumentMatchers.any;
2214
import static org.mockito.ArgumentMatchers.anyInt;
2315
import static org.mockito.ArgumentMatchers.anyString;
2416
import static org.mockito.ArgumentMatchers.isNull;
2517
import static org.mockito.Mockito.times;
2618
import static org.mockito.Mockito.verify;
2719

28-
public class LockScreenDeviceIconManagerTests extends AndroidTestCase2 {
20+
@RunWith(AndroidJUnit4.class)
21+
public class LockScreenDeviceIconManagerTests {
2922

3023
TemporaryFolder tempFolder = new TemporaryFolder();
3124
private LockScreenDeviceIconManager lockScreenDeviceIconManager;
3225
private static final String ICON_URL = "https://i.imgur.com/TgkvOIZ.png";
3326
private static final String LAST_UPDATED_TIME = "lastUpdatedTime";
3427
private static final String STORED_PATH = "storedPath";
3528

36-
public void setup() throws Exception {
37-
super.setUp();
38-
}
39-
40-
public void tearDown() throws Exception {
41-
super.tearDown();
42-
}
43-
29+
@Test
4430
public void testRetrieveIconShouldCallOnErrorTwiceWhenGivenURLThatCannotDownloadAndIconIsNotCached() {
4531
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
4632
final Context context = Mockito.mock(Context.class);
@@ -54,6 +40,7 @@ public void testRetrieveIconShouldCallOnErrorTwiceWhenGivenURLThatCannotDownload
5440
verify(listener, times(2)).onError(anyString());
5541
}
5642

43+
@Test
5744
public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenIconUpdateTimeIsNullFromSharedPref() {
5845
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
5946
final Context context = Mockito.mock(Context.class);
@@ -67,7 +54,7 @@ public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenIconUpd
6754
verify(listener, times(1)).onImageRetrieved((Bitmap) any());
6855
}
6956

70-
57+
@Test
7158
public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenCachedIconExpired() {
7259
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
7360
final Context context = Mockito.mock(Context.class);
@@ -81,6 +68,7 @@ public void testRetrieveIconShouldCallOnImageOnImageRetrievedWithIconWhenCachedI
8168
verify(listener, times(1)).onImageRetrieved((Bitmap) any());
8269
}
8370

71+
@Test
8472
public void testRetrieveIconShouldCallOnImageRetrievedWithIconWhenCachedIconIsUpToDate() {
8573
final SharedPreferences sharedPrefs = Mockito.mock(SharedPreferences.class);
8674
final Context context = Mockito.mock(Context.class);

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/LockScreenManagerTests.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.smartdevicelink.managers.lockscreen;
22

33
import android.content.Context;
4+
import android.support.test.runner.AndroidJUnit4;
45

5-
import com.smartdevicelink.AndroidTestCase2;
66
import com.smartdevicelink.protocol.enums.FunctionID;
77
import com.smartdevicelink.proxy.interfaces.ISdl;
88
import com.smartdevicelink.proxy.rpc.OnDriverDistraction;
@@ -12,9 +12,17 @@
1212
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
1313
import com.smartdevicelink.test.TestValues;
1414

15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
1518
import org.mockito.invocation.InvocationOnMock;
1619
import org.mockito.stubbing.Answer;
1720

21+
import static android.support.test.InstrumentationRegistry.getContext;
22+
import static junit.framework.TestCase.assertEquals;
23+
import static junit.framework.TestCase.assertFalse;
24+
import static junit.framework.TestCase.assertNull;
25+
import static junit.framework.TestCase.assertTrue;
1826
import static org.mockito.ArgumentMatchers.any;
1927
import static org.mockito.ArgumentMatchers.eq;
2028
import static org.mockito.Mockito.doAnswer;
@@ -24,14 +32,14 @@
2432
* This is a unit test class for the SmartDeviceLink library manager class :
2533
* {@link com.smartdevicelink.managers.lockscreen.LockScreenManager}
2634
*/
27-
public class LockScreenManagerTests extends AndroidTestCase2 {
35+
@RunWith(AndroidJUnit4.class)
36+
public class LockScreenManagerTests {
2837

2938
private LockScreenManager lockScreenManager;
3039
private OnRPCNotificationListener onDDListener;
3140

32-
@Override
41+
@Before
3342
public void setUp() throws Exception{
34-
super.setUp();
3543

3644
ISdl internalInterface = mock(ISdl.class);
3745

@@ -58,11 +66,7 @@ public Void answer(InvocationOnMock invocation) {
5866
lockScreenManager = new LockScreenManager(lockScreenConfig, context, internalInterface);
5967
}
6068

61-
@Override
62-
public void tearDown() throws Exception {
63-
super.tearDown();
64-
}
65-
69+
@Test
6670
public void testVariables() {
6771
assertEquals(TestValues.GENERAL_INT, lockScreenManager.customView);
6872
assertEquals(TestValues.GENERAL_INT, lockScreenManager.lockScreenIcon);
@@ -73,48 +77,56 @@ public void testVariables() {
7377
assertEquals(LockScreenConfig.DISPLAY_MODE_OPTIONAL_OR_REQUIRED, lockScreenManager.displayMode);
7478
}
7579

80+
@Test
7681
public void testGetLockScreenStatusHmiNoneDDOff(){
7782
lockScreenManager.driverDistStatus = false;
7883
lockScreenManager.hmiLevel = HMILevel.HMI_NONE;
7984
assertEquals(LockScreenStatus.OFF, lockScreenManager.getLockScreenStatus());
8085
}
8186

87+
@Test
8288
public void testGetLockScreenStatusHmiBackgroundDDOff(){
8389
lockScreenManager.driverDistStatus = false;
8490
lockScreenManager.hmiLevel = HMILevel.HMI_BACKGROUND;
8591
assertEquals(LockScreenStatus.OFF, lockScreenManager.getLockScreenStatus());
8692
}
8793

94+
@Test
8895
public void testGetLockScreenStatusHmiNoneDDOn(){
8996
lockScreenManager.driverDistStatus = true;
9097
lockScreenManager.hmiLevel = HMILevel.HMI_BACKGROUND;
9198
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
9299
}
93100

101+
@Test
94102
public void testGetLockScreenStatusHmiFullDDOff(){
95103
lockScreenManager.driverDistStatus = false;
96104
lockScreenManager.hmiLevel = HMILevel.HMI_FULL;
97105
assertEquals(LockScreenStatus.OPTIONAL, lockScreenManager.getLockScreenStatus());
98106
}
99107

108+
@Test
100109
public void testGetLockScreenStatusHmiFullDDOn(){
101110
lockScreenManager.driverDistStatus = true;
102111
lockScreenManager.hmiLevel = HMILevel.HMI_FULL;
103112
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
104113
}
105114

115+
@Test
106116
public void testGetLockScreenStatusHmiLimitedDDOff(){
107117
lockScreenManager.driverDistStatus = false;
108118
lockScreenManager.hmiLevel = HMILevel.HMI_LIMITED;
109119
assertEquals(LockScreenStatus.OPTIONAL, lockScreenManager.getLockScreenStatus());
110120
}
111121

122+
@Test
112123
public void testGetLockScreenStatusHmiLimitedDDOn(){
113124
lockScreenManager.driverDistStatus = true;
114125
lockScreenManager.hmiLevel = HMILevel.HMI_LIMITED;
115126
assertEquals(LockScreenStatus.REQUIRED, lockScreenManager.getLockScreenStatus());
116127
}
117128

129+
@Test
118130
public void testLockScreenDismissibleWithEnableTrueAndDismissibilityTrue(){
119131
lockScreenManager.enableDismissGesture = true;
120132
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
@@ -125,6 +137,7 @@ public void testLockScreenDismissibleWithEnableTrueAndDismissibilityTrue(){
125137
assertTrue(lockScreenManager.mIsLockscreenDismissible);
126138
}
127139

140+
@Test
128141
public void testLockScreenDismissibleWithEnableFalseAndDismissibilityFalse(){
129142
lockScreenManager.enableDismissGesture = false;
130143
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
@@ -135,6 +148,7 @@ public void testLockScreenDismissibleWithEnableFalseAndDismissibilityFalse(){
135148
assertFalse(lockScreenManager.mIsLockscreenDismissible);
136149
}
137150

151+
@Test
138152
public void testLockScreenDismissibleWithEnableTrueAndDismissibilityFalse(){
139153
lockScreenManager.enableDismissGesture = true;
140154
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
@@ -145,6 +159,7 @@ public void testLockScreenDismissibleWithEnableTrueAndDismissibilityFalse(){
145159
assertFalse(lockScreenManager.mIsLockscreenDismissible);
146160
}
147161

162+
@Test
148163
public void testLockScreenDismissibleWithEnableFalseAndDismissibilityTrue(){
149164
lockScreenManager.enableDismissGesture = false;
150165
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/permission/PermissionManagerTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.smartdevicelink.managers.permission;
22

33
import android.support.annotation.NonNull;
4+
import android.support.test.runner.AndroidJUnit4;
45

5-
import com.smartdevicelink.AndroidTestCase2;
66
import com.smartdevicelink.protocol.enums.FunctionID;
77
import com.smartdevicelink.proxy.interfaces.ISdl;
88
import com.smartdevicelink.proxy.rpc.HMIPermissions;
@@ -13,6 +13,9 @@
1313
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
1414
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
1515

16+
import org.junit.Before;
17+
import org.junit.Test;
18+
import org.junit.runner.RunWith;
1619
import org.mockito.invocation.InvocationOnMock;
1720
import org.mockito.stubbing.Answer;
1821

@@ -22,25 +25,26 @@
2225
import java.util.Map;
2326

2427
import static com.smartdevicelink.managers.permission.BasePermissionManager.PERMISSION_GROUP_STATUS_DISALLOWED;
25-
import static com.smartdevicelink.managers.permission.BasePermissionManager.PERMISSION_GROUP_STATUS_UNKNOWN;
2628
import static com.smartdevicelink.managers.permission.PermissionManager.PERMISSION_GROUP_STATUS_ALLOWED;
2729
import static com.smartdevicelink.managers.permission.PermissionManager.PERMISSION_GROUP_STATUS_MIXED;
30+
import static junit.framework.TestCase.assertEquals;
2831
import static junit.framework.TestCase.assertFalse;
32+
import static junit.framework.TestCase.assertTrue;
2933
import static org.mockito.ArgumentMatchers.any;
3034
import static org.mockito.ArgumentMatchers.eq;
3135
import static org.mockito.Mockito.doAnswer;
3236
import static org.mockito.Mockito.mock;
3337

34-
public class PermissionManagerTests extends AndroidTestCase2 {
38+
@RunWith(AndroidJUnit4.class)
39+
public class PermissionManagerTests {
3540

3641
private OnRPCNotificationListener onHMIStatusListener, onPermissionsChangeListener;
3742
private PermissionManager permissionManager;
3843
private int listenerCalledCounter;
3944

4045

41-
@Override
42-
protected void setUp() throws Exception {
43-
super.setUp();
46+
@Before
47+
public void setUp() throws Exception {
4448

4549

4650
// Mock Isdl and its behaviour to use it for PermissionManager testing
@@ -98,6 +102,7 @@ private void sendFakeCoreOnPermissionsChangeNotifications(List<PermissionItem> p
98102
}
99103

100104
// Test adding a listener to be called when ALL of the specified permissions become allowed
105+
@Test
101106
public void testListenersAllAllowed() {
102107
listenerCalledCounter = 0;
103108

@@ -149,6 +154,7 @@ public void onPermissionsChange(@NonNull Map<FunctionID, PermissionStatus> allow
149154

150155

151156
// Test adding a listener to be called when ANY of the specified permissions become allowed
157+
@Test
152158
public void testListenersAnyAllowed() {
153159
listenerCalledCounter = 0;
154160

0 commit comments

Comments
 (0)