Skip to content

Commit 0996f6c

Browse files
committed
Update more tests for AndroidJUnit4
1 parent e0bef51 commit 0996f6c

3 files changed

Lines changed: 45 additions & 24 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,36 @@
44
import android.os.Handler;
55
import android.os.Looper;
66
import android.os.Message;
7+
import android.support.test.runner.AndroidJUnit4;
78

8-
import com.smartdevicelink.AndroidTestCase2;
99
import com.smartdevicelink.protocol.SdlPacket;
1010
import com.smartdevicelink.test.SdlUnitTestContants;
1111
import com.smartdevicelink.transport.enums.TransportType;
1212

1313
import junit.framework.Assert;
1414

15-
public class MultiplexTransportTest extends AndroidTestCase2 {
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
19+
import static android.support.test.InstrumentationRegistry.getContext;
20+
import static junit.framework.TestCase.assertEquals;
21+
import static junit.framework.TestCase.assertNotNull;
22+
import static junit.framework.TestCase.assertNull;
23+
import static junit.framework.TestCase.assertTrue;
24+
25+
@RunWith(AndroidJUnit4.class)
26+
public class MultiplexTransportTest {
1627

1728
private static final int TIMEOUT = 2000;
1829

1930
RouterServiceValidator rsvp;
2031
ITransportListener transportListener;
2132

2233

23-
@Override
24-
protected void setUp() throws Exception {
25-
super.setUp();
26-
rsvp = new RouterServiceValidator(this.mContext);
34+
@Before
35+
public void setUp() throws Exception {
36+
rsvp = new RouterServiceValidator(getContext());
2737
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
2838
rsvp.validate();
2939

@@ -49,9 +59,9 @@ public void onTransportError(String info, Exception e) {
4959

5060
}
5161

52-
62+
@Test
5363
public void testThreadRecoverability(){
54-
MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
64+
MultiplexTransportConfig config = new MultiplexTransportConfig(getContext(),SdlUnitTestContants.TEST_APP_ID);
5565
// public MultiplexTransport(MultiplexTransportConfig transportConfig, final ITransportListener transportListener){
5666
MultiplexTransport trans = new MultiplexTransport(config,transportListener);
5767

android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
import android.os.Looper;
44
import android.os.Messenger;
5+
import android.support.test.runner.AndroidJUnit4;
56

6-
import com.smartdevicelink.AndroidTestCase2;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static junit.framework.TestCase.assertNotNull;
11+
import static junit.framework.TestCase.assertNull;
712

813

914
/**
1015
* Created by brettywhite on 4/4/17.
1116
*/
12-
13-
public class RegisteredAppTests extends AndroidTestCase2 {
17+
@RunWith(AndroidJUnit4.class)
18+
public class RegisteredAppTests {
1419

1520
private static final String APP_ID = "123451123";
1621
private static final Messenger messenger = null;
1722
private static byte[] bytes = new byte[1];
1823

24+
@Test
1925
public void testHandleMessage() {
2026

2127
if (Looper.myLooper() == null) {
@@ -35,6 +41,7 @@ public void testHandleMessage() {
3541

3642
}
3743

44+
@Test
3845
public void testNullBuffer() {
3946

4047
if (Looper.myLooper() == null) {

android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import android.os.Handler;
66
import android.os.Looper;
77
import android.os.Message;
8+
import android.support.test.runner.AndroidJUnit4;
89
import android.util.Log;
910
import android.util.SparseArray;
1011
import android.util.SparseIntArray;
1112

12-
import com.smartdevicelink.AndroidTestCase2;
1313
import com.smartdevicelink.marshal.JsonRPCMarshaller;
1414
import com.smartdevicelink.protocol.BinaryFrameHeader;
1515
import com.smartdevicelink.protocol.ProtocolMessage;
@@ -25,6 +25,8 @@
2525

2626
import junit.framework.Assert;
2727

28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
2830
import org.mockito.ArgumentCaptor;
2931

3032
import java.lang.ref.WeakReference;
@@ -36,6 +38,8 @@
3638
import java.util.List;
3739
import java.util.Vector;
3840

41+
import static android.support.test.InstrumentationRegistry.getContext;
42+
import static junit.framework.TestCase.assertEquals;
3943
import static org.mockito.ArgumentMatchers.any;
4044
import static org.mockito.ArgumentMatchers.anyInt;
4145
import static org.mockito.ArgumentMatchers.eq;
@@ -44,7 +48,8 @@
4448
import static org.mockito.Mockito.verify;
4549
import static org.mockito.Mockito.when;
4650

47-
public class SdlRouterServiceTests extends AndroidTestCase2 {
51+
@RunWith(AndroidJUnit4.class)
52+
public class SdlRouterServiceTests {
4853

4954
public static final String TAG = "SdlRouterServiceTests";
5055
private final int SAMPLE_RPC_CORRELATION_ID = 630;
@@ -53,21 +58,11 @@ public class SdlRouterServiceTests extends AndroidTestCase2 {
5358
ProtocolMessage pm = null;
5459
BinaryFrameHeader binFrameHeader = null;
5560

56-
@Override
57-
protected void setUp() throws Exception {
58-
super.setUp();
59-
}
60-
61-
@Override
62-
protected void tearDown() throws Exception {
63-
super.tearDown();
64-
//Nothing here for now
65-
}
66-
6761
/**
6862
* Ensure that the router service hardcoded number is the same as the integer value in
6963
* the resources.
7064
*/
65+
@Test
7166
public void testVersionCorrectness(){
7267
int resourceVersion = getContext().getResources().getInteger(com.smartdevicelink.test.R.integer.sdl_router_service_version_value);
7368
assertEquals(resourceVersion, SdlRouterService.ROUTER_SERVICE_VERSION_NUMBER);
@@ -77,6 +72,7 @@ public void testVersionCorrectness(){
7772
* Test null bundle handling in AltTransportHandler when handling messages. Only test the case of
7873
* msg.what == TransportConstants.ROUTER_RECEIVED_PACKET
7974
*/
75+
@Test
8076
public void testAlTransportHandlerHandleNullBundle() {
8177
if (Looper.myLooper() == null) {
8278
Looper.prepare();
@@ -134,6 +130,7 @@ public void handleMessage(Message msg) {
134130
*
135131
* @see SdlRouterService#writeBytesToTransport(Bundle)
136132
*/
133+
@Test
137134
public void testWriteBytesToTransport() {
138135
if (Looper.myLooper() == null) {
139136
Looper.prepare();
@@ -178,6 +175,7 @@ public void testWriteBytesToTransport() {
178175
*
179176
* @see SdlRouterService#sendPacketToRegisteredApp(SdlPacket)
180177
*/
178+
@Test
181179
public void testRegisterAppExistingSessionIDDifferentApp() {
182180
if (Looper.myLooper() == null) {
183181
Looper.prepare();
@@ -270,6 +268,7 @@ public void testRegisterAppExistingSessionIDDifferentApp() {
270268
*
271269
* @see SdlRouterService#sendPacketToRegisteredApp(SdlPacket)
272270
*/
271+
@Test
273272
public void testRegisterAppExistingSessionIDSameApp() {
274273
if (Looper.myLooper() == null) {
275274
Looper.prepare();
@@ -360,6 +359,7 @@ public void testRegisterAppExistingSessionIDSameApp() {
360359
/**
361360
* Test router service correctly picks up Hash ID from start service ACK (prior to V5)
362361
*/
362+
@Test
363363
public void testStartSessionAckHashId() {
364364
if (Looper.myLooper() == null) {
365365
Looper.prepare();
@@ -398,6 +398,7 @@ public void testStartSessionAckHashId() {
398398
/**
399399
* Test router service correctly acquires Hash ID from V5 start service ACK
400400
*/
401+
@Test
401402
public void testStartSessionAckV5HashId() {
402403
if (Looper.myLooper() == null) {
403404
Looper.prepare();
@@ -439,6 +440,7 @@ public void testStartSessionAckV5HashId() {
439440
/**
440441
* Test router service sends a valid end service request from attemptToCleanupModule()
441442
*/
443+
@Test
442444
public void testEndSessionV5FromAttemptToCleanupModule() {
443445
if (Looper.myLooper() == null) {
444446
Looper.prepare();
@@ -506,6 +508,7 @@ public void testEndSessionV5FromAttemptToCleanupModule() {
506508
* Test router service sends a valid end service request when it receives a packet from Core
507509
* and the app has been unregistered
508510
*/
511+
@Test
509512
public void testEndSessionV5WhenPacketForUnregisteredAppReceived() {
510513
if (Looper.myLooper() == null) {
511514
Looper.prepare();
@@ -584,6 +587,7 @@ public void testEndSessionV5WhenPacketForUnregisteredAppReceived() {
584587
* Test router service sends a valid end service request when it fails to deliver a message
585588
* to an app
586589
*/
590+
@Test
587591
public void testEndSessionV5WhenSendMessageToClientFailed() {
588592
if (Looper.myLooper() == null) {
589593
Looper.prepare();

0 commit comments

Comments
 (0)