diff options
author | RHenigan <heniganr1@gmail.com> | 2020-06-15 16:04:11 -0400 |
---|---|---|
committer | RHenigan <heniganr1@gmail.com> | 2020-06-15 16:04:11 -0400 |
commit | 0996f6cbbf143e219ca27b22390835c61e3cfac0 (patch) | |
tree | e8f695f816ed1915ea52957246d893c40afd4fb0 /android | |
parent | e0bef51a64117e6bf5c6cb8898e5f0a479395905 (diff) | |
download | sdl_android-0996f6cbbf143e219ca27b22390835c61e3cfac0.tar.gz |
Update more tests for AndroidJUnit4
Diffstat (limited to 'android')
3 files changed, 45 insertions, 24 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java index b2da5ef08..8f145b12f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/MultiplexTransportTest.java @@ -4,15 +4,26 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.support.test.runner.AndroidJUnit4; -import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.protocol.SdlPacket; import com.smartdevicelink.test.SdlUnitTestContants; import com.smartdevicelink.transport.enums.TransportType; import junit.framework.Assert; -public class MultiplexTransportTest extends AndroidTestCase2 { +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.InstrumentationRegistry.getContext; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertNull; +import static junit.framework.TestCase.assertTrue; + +@RunWith(AndroidJUnit4.class) +public class MultiplexTransportTest { private static final int TIMEOUT = 2000; @@ -20,10 +31,9 @@ public class MultiplexTransportTest extends AndroidTestCase2 { ITransportListener transportListener; - @Override - protected void setUp() throws Exception { - super.setUp(); - rsvp = new RouterServiceValidator(this.mContext); + @Before + public void setUp() throws Exception { + rsvp = new RouterServiceValidator(getContext()); rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE); rsvp.validate(); @@ -49,9 +59,9 @@ public class MultiplexTransportTest extends AndroidTestCase2 { } - + @Test public void testThreadRecoverability(){ - MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID); + MultiplexTransportConfig config = new MultiplexTransportConfig(getContext(),SdlUnitTestContants.TEST_APP_ID); // public MultiplexTransport(MultiplexTransportConfig transportConfig, final ITransportListener transportListener){ MultiplexTransport trans = new MultiplexTransport(config,transportListener); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java index 89dbae3ab..2cf70d1be 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java @@ -2,20 +2,26 @@ package com.smartdevicelink.transport; import android.os.Looper; import android.os.Messenger; +import android.support.test.runner.AndroidJUnit4; -import com.smartdevicelink.AndroidTestCase2; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertNull; /** * Created by brettywhite on 4/4/17. */ - -public class RegisteredAppTests extends AndroidTestCase2 { +@RunWith(AndroidJUnit4.class) +public class RegisteredAppTests { private static final String APP_ID = "123451123"; private static final Messenger messenger = null; private static byte[] bytes = new byte[1]; + @Test public void testHandleMessage() { if (Looper.myLooper() == null) { @@ -35,6 +41,7 @@ public class RegisteredAppTests extends AndroidTestCase2 { } + @Test public void testNullBuffer() { if (Looper.myLooper() == null) { diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java index e01fdbaf2..5995b457f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java @@ -5,11 +5,11 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.support.test.runner.AndroidJUnit4; import android.util.Log; import android.util.SparseArray; import android.util.SparseIntArray; -import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.protocol.BinaryFrameHeader; import com.smartdevicelink.protocol.ProtocolMessage; @@ -25,6 +25,8 @@ import com.smartdevicelink.transport.utl.TransportRecord; import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import java.lang.ref.WeakReference; @@ -36,6 +38,8 @@ import java.util.HashMap; import java.util.List; import java.util.Vector; +import static android.support.test.InstrumentationRegistry.getContext; +import static junit.framework.TestCase.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; @@ -44,7 +48,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class SdlRouterServiceTests extends AndroidTestCase2 { +@RunWith(AndroidJUnit4.class) +public class SdlRouterServiceTests { public static final String TAG = "SdlRouterServiceTests"; private final int SAMPLE_RPC_CORRELATION_ID = 630; @@ -53,21 +58,11 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { ProtocolMessage pm = null; BinaryFrameHeader binFrameHeader = null; - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - //Nothing here for now - } - /** * Ensure that the router service hardcoded number is the same as the integer value in * the resources. */ + @Test public void testVersionCorrectness(){ int resourceVersion = getContext().getResources().getInteger(com.smartdevicelink.test.R.integer.sdl_router_service_version_value); assertEquals(resourceVersion, SdlRouterService.ROUTER_SERVICE_VERSION_NUMBER); @@ -77,6 +72,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * Test null bundle handling in AltTransportHandler when handling messages. Only test the case of * msg.what == TransportConstants.ROUTER_RECEIVED_PACKET */ + @Test public void testAlTransportHandlerHandleNullBundle() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -134,6 +130,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * * @see SdlRouterService#writeBytesToTransport(Bundle) */ + @Test public void testWriteBytesToTransport() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -178,6 +175,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * * @see SdlRouterService#sendPacketToRegisteredApp(SdlPacket) */ + @Test public void testRegisterAppExistingSessionIDDifferentApp() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -270,6 +268,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * * @see SdlRouterService#sendPacketToRegisteredApp(SdlPacket) */ + @Test public void testRegisterAppExistingSessionIDSameApp() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -360,6 +359,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { /** * Test router service correctly picks up Hash ID from start service ACK (prior to V5) */ + @Test public void testStartSessionAckHashId() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -398,6 +398,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { /** * Test router service correctly acquires Hash ID from V5 start service ACK */ + @Test public void testStartSessionAckV5HashId() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -439,6 +440,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { /** * Test router service sends a valid end service request from attemptToCleanupModule() */ + @Test public void testEndSessionV5FromAttemptToCleanupModule() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -506,6 +508,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * Test router service sends a valid end service request when it receives a packet from Core * and the app has been unregistered */ + @Test public void testEndSessionV5WhenPacketForUnregisteredAppReceived() { if (Looper.myLooper() == null) { Looper.prepare(); @@ -584,6 +587,7 @@ public class SdlRouterServiceTests extends AndroidTestCase2 { * Test router service sends a valid end service request when it fails to deliver a message * to an app */ + @Test public void testEndSessionV5WhenSendMessageToClientFailed() { if (Looper.myLooper() == null) { Looper.prepare(); |