Skip to content

Commit e0bef51

Browse files
committed
Refactor some test classes for AndroidJUnit4
1 parent 6b52e38 commit e0bef51

11 files changed

Lines changed: 179 additions & 71 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java

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

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

5-
import com.smartdevicelink.AndroidTestCase2;
66
import com.smartdevicelink.managers.lifecycle.LifecycleConfigurationUpdate;
77
import com.smartdevicelink.managers.lockscreen.LockScreenConfig;
88
import com.smartdevicelink.protocol.enums.FunctionID;
@@ -24,6 +24,8 @@
2424
import com.smartdevicelink.transport.BaseTransportConfig;
2525
import com.smartdevicelink.transport.TCPTransportConfig;
2626

27+
import org.junit.Before;
28+
import org.junit.runner.RunWith;
2729
import org.mockito.Mockito;
2830
import org.mockito.invocation.InvocationOnMock;
2931
import org.mockito.stubbing.Answer;
@@ -32,6 +34,10 @@
3234
import java.util.List;
3335
import java.util.Vector;
3436

37+
import static junit.framework.TestCase.assertEquals;
38+
import static junit.framework.TestCase.assertNotNull;
39+
import static junit.framework.TestCase.assertSame;
40+
import static junit.framework.TestCase.assertTrue;
3541
import static org.mockito.ArgumentMatchers.any;
3642
import static org.mockito.Mockito.doAnswer;
3743
import static org.mockito.Mockito.mock;
@@ -40,7 +46,8 @@
4046
* This is a unit test class for the SmartDeviceLink library manager class :
4147
* {@link com.smartdevicelink.managers.SdlManager}
4248
*/
43-
public class SdlManagerTests extends AndroidTestCase2 {
49+
@RunWith(AndroidJUnit4.class)
50+
public class SdlManagerTests {
4451

4552
public static BaseTransportConfig transport = null;
4653
private Context mTestContext;
@@ -56,10 +63,8 @@ public class SdlManagerTests extends AndroidTestCase2 {
5663
@SuppressWarnings("FieldCanBeLocal")
5764
private String DEV_MACHINE_IP_ADDRESS = "0.0.0.0";
5865

59-
@Override
66+
@Before
6067
public void setUp() throws Exception{
61-
super.setUp();
62-
6368
mTestContext = Mockito.mock(Context.class);
6469

6570
// set transport
@@ -78,11 +83,6 @@ public void setUp() throws Exception{
7883
sdlManager = createSampleManager("heyApp", "123456", Test.GENERAL_LOCKSCREENCONFIG);
7984
}
8085

81-
@Override
82-
public void tearDown() throws Exception {
83-
super.tearDown();
84-
}
85-
8686
// SETUP / HELPERS
8787

8888
private Context getTestContext() {
@@ -144,10 +144,12 @@ public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language langua
144144

145145
// TESTS
146146

147+
@org.junit.Test
147148
public void testNotNull(){
148149
assertNotNull(createSampleManager("app","123456", Test.GENERAL_LOCKSCREENCONFIG));
149150
}
150151

152+
@org.junit.Test
151153
public void testMissingAppName() {
152154
try {
153155
createSampleManager(null,"123456", Test.GENERAL_LOCKSCREENCONFIG);
@@ -156,6 +158,7 @@ public void testMissingAppName() {
156158
}
157159
}
158160

161+
@org.junit.Test
159162
public void testMissingAppId() {
160163
try {
161164
createSampleManager("app",null, Test.GENERAL_LOCKSCREENCONFIG);
@@ -164,6 +167,7 @@ public void testMissingAppId() {
164167
}
165168
}
166169

170+
@org.junit.Test
167171
public void testManagerSetters() {
168172
assertEquals("123456", sdlManager.getAppId());
169173
assertEquals("heyApp", sdlManager.getAppName());
@@ -181,6 +185,7 @@ public void testManagerSetters() {
181185
assertEquals(Test.GENERAL_VERSION, sdlManager.getMinimumRPCVersion());
182186
}
183187

188+
@org.junit.Test
184189
public void testStartingManager(){
185190
listenerCalledCounter = 0;
186191

@@ -203,6 +208,7 @@ public void testStartingManager(){
203208
assertEquals("Listener was not called or called more/less frequently than expected", 1, listenerCalledCounter);
204209
}
205210

211+
@org.junit.Test
206212
public void testManagerStates() {
207213
SdlManager sdlManager = createSampleManager("test", "00000", new LockScreenConfig());
208214
sdlManager.initialize();
@@ -313,6 +319,7 @@ public void testManagerStates() {
313319
assertEquals(BaseSubManager.SHUTDOWN, sdlManager.getState());
314320
}
315321

322+
@org.junit.Test
316323
public void testSendRPC(){
317324
listenerCalledCounter = 0;
318325

@@ -348,10 +355,12 @@ public void onResponse(int correlationId, RPCResponse response) {
348355
assertEquals("Listener was not called or called more/less frequently than expected", 1, listenerCalledCounter);
349356
}
350357

358+
@org.junit.Test
351359
public void testSendRPCs(){
352360
testSendMultipleRPCs(false);
353361
}
354362

363+
@org.junit.Test
355364
public void testSendSequentialRPCs(){
356365
testSendMultipleRPCs(true);
357366
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import android.content.Context;
44
import android.net.Uri;
5+
import android.support.test.runner.AndroidJUnit4;
56

6-
import com.smartdevicelink.AndroidTestCase2;
77
import com.smartdevicelink.managers.BaseSubManager;
88
import com.smartdevicelink.managers.CompletionListener;
99
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
@@ -23,13 +23,20 @@
2323
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
2424
import com.smartdevicelink.test.Test;
2525

26+
import org.junit.Before;
27+
import org.junit.runner.RunWith;
2628
import org.mockito.invocation.InvocationOnMock;
2729
import org.mockito.stubbing.Answer;
2830

2931
import java.util.ArrayList;
3032
import java.util.List;
3133
import java.util.Map;
3234

35+
import static android.support.test.InstrumentationRegistry.getContext;
36+
import static junit.framework.TestCase.assertTrue;
37+
import static org.junit.Assert.assertEquals;
38+
import static org.junit.Assert.assertFalse;
39+
import static org.junit.Assert.assertNull;
3340
import static org.mockito.ArgumentMatchers.any;
3441
import static org.mockito.Mockito.doAnswer;
3542
import static org.mockito.Mockito.mock;
@@ -40,28 +47,23 @@
4047
* This is a unit test class for the SmartDeviceLink library manager class :
4148
* {@link FileManager}
4249
*/
43-
public class FileManagerTests extends AndroidTestCase2 {
50+
@RunWith(AndroidJUnit4.class)
51+
public class FileManagerTests {
4452
public static final String TAG = "FileManagerTests";
4553
private Context mTestContext;
4654
private SdlFile validFile;
4755

4856
// SETUP / HELPERS
4957

50-
@Override
58+
@Before
5159
public void setUp() throws Exception{
52-
super.setUp();
53-
mTestContext = this.getContext();
60+
mTestContext = getContext();
5461
validFile = new SdlFile();
5562
validFile.setName(Test.GENERAL_STRING);
5663
validFile.setFileData(Test.GENERAL_BYTE_ARRAY);
5764
validFile.setPersistent(false);
5865
}
5966

60-
@Override
61-
public void tearDown() throws Exception {
62-
super.tearDown();
63-
}
64-
6567
private Answer<Void> onPutFileFailureOnError = new Answer<Void>() {
6668
@Override
6769
public Void answer(InvocationOnMock invocation) throws Throwable {
@@ -242,6 +244,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
242244
/**
243245
* Test deleting list of files, success
244246
*/
247+
@org.junit.Test
245248
public void testDeleteRemoteFilesWithNamesSuccess(){
246249
final ISdl internalInterface = mock(ISdl.class);
247250

@@ -273,6 +276,7 @@ public void onComplete(Map<String, String> errors) {
273276
/**
274277
* Test deleting list of files, fail
275278
*/
279+
@org.junit.Test
276280
public void testDeleteRemoteFilesWithNamesFail(){
277281
final ISdl internalInterface = mock(ISdl.class);
278282

@@ -304,6 +308,7 @@ public void onComplete(Map<String, String> errors) {
304308
/**
305309
* Test reUploading failed file
306310
*/
311+
@org.junit.Test
307312
public void testFileUploadRetry(){
308313
final ISdl internalInterface = mock(ISdl.class);
309314

@@ -335,6 +340,7 @@ public void onComplete(boolean success) {
335340
/**
336341
* Test reUploading failed Artwork
337342
*/
343+
@org.junit.Test
338344
public void testArtworkUploadRetry(){
339345
final ISdl internalInterface = mock(ISdl.class);
340346

@@ -393,6 +399,7 @@ public void onComplete(boolean success) {
393399
/**
394400
* Test retry uploading failed list of files
395401
*/
402+
@org.junit.Test
396403
public void testListFilesUploadRetry(){
397404
final ISdl internalInterface = mock(ISdl.class);
398405

@@ -434,6 +441,7 @@ public void onComplete(Map<String, String> errors) {
434441
/**
435442
* Testing the initialization of FileManager
436443
*/
444+
@org.junit.Test
437445
public void testInitializationSuccess() {
438446
ISdl internalInterface = mock(ISdl.class);
439447

@@ -455,6 +463,7 @@ public void onComplete(boolean success) {
455463
/**
456464
* Test file upload, success
457465
*/
466+
@org.junit.Test
458467
public void testFileUploadSuccess() {
459468
ISdl internalInterface = mock(ISdl.class);
460469

@@ -484,6 +493,7 @@ public void onComplete(boolean success) {
484493
/**
485494
* Testing failed file upload.
486495
*/
496+
@org.junit.Test
487497
public void testFileUploadFailure() {
488498
ISdl internalInterface = mock(ISdl.class);
489499

@@ -511,6 +521,7 @@ public void onComplete(boolean success) {
511521
/**
512522
* Testing uploadFile for a staticIcon, verifying that it doesn't actually upload.
513523
*/
524+
@org.junit.Test
514525
public void testFileUploadForStaticIcon() {
515526
ISdl internalInterface = mock(ISdl.class);
516527

@@ -537,6 +548,7 @@ public void onComplete(boolean success) {
537548
/**
538549
* Testing uploadFiles for staticIcons, verifying that it doesn't actually upload.
539550
*/
551+
@org.junit.Test
540552
public void testMultipleFileUploadsForStaticIcon() {
541553
ISdl internalInterface = mock(ISdl.class);
542554

@@ -568,6 +580,7 @@ public void onComplete(Map<String, String> errors) {
568580
/**
569581
* Testing uploadFiles for static icons and nonStatic icons in the same list.
570582
*/
583+
@org.junit.Test
571584
public void testMultipleFileUploadsForPartialStaticIcon() {
572585
ISdl internalInterface = mock(ISdl.class);
573586

@@ -600,6 +613,7 @@ public void onComplete(Map<String, String> errors) {
600613
/**
601614
* Test to make sure you cannot upload an SdlFile with invalid data
602615
*/
616+
@org.junit.Test
603617
public void testInvalidSdlFileInput() {
604618
ISdl internalInterface = mock(ISdl.class);
605619

@@ -662,6 +676,7 @@ public void onComplete(boolean success) {}
662676
* Test Invalid SdlArtWork FileTypes
663677
* SdlArtwork FileTypes can only be: GRAPHIC_BMP, GRAPHIC_PNG or GRAPHIC_JPEG
664678
*/
679+
@org.junit.Test
665680
public void testInvalidSdlArtworkInput(){
666681
SdlArtwork sdlArtwork = new SdlArtwork();
667682
// Set invalid type
@@ -683,6 +698,7 @@ public void testInvalidSdlArtworkInput(){
683698
/**
684699
* Test Multiple File Uploads, success
685700
*/
701+
@org.junit.Test
686702
public void testMultipleFileUpload() {
687703
ISdl internalInterface = mock(ISdl.class);
688704

@@ -719,6 +735,7 @@ public void onComplete(Map<String, String> errors) {
719735
/**
720736
* Testing uploading multiple files with some failing.
721737
*/
738+
@org.junit.Test
722739
public void testMultipleFileUploadPartialFailure() {
723740
ISdl internalInterface = mock(ISdl.class);
724741

@@ -767,6 +784,7 @@ public void onComplete(Map<String, String> errors) {
767784
/**
768785
* Testing uploading multiple SdlArtwork files.
769786
*/
787+
@org.junit.Test
770788
public void testMultipleArtworkUploadSuccess(){
771789
ISdl internalInterface = mock(ISdl.class);
772790

@@ -813,6 +831,7 @@ public void onComplete(Map<String, String> errors) {
813831
/**
814832
* Testing uploading persistent SdlFile
815833
*/
834+
@org.junit.Test
816835
public void testPersistentFileUploaded(){
817836
ISdl internalInterface = mock(ISdl.class);
818837

@@ -835,6 +854,7 @@ public void onComplete(boolean success) {
835854
/**
836855
* Test FileManagerConfig
837856
*/
857+
@org.junit.Test
838858
public void testFileManagerConfig() {
839859
FileManagerConfig fileManagerConfig = new FileManagerConfig();
840860
fileManagerConfig.setFileRetryCount(2);
@@ -847,6 +867,7 @@ public void testFileManagerConfig() {
847867
* Tests overwrite property for uploading a file.
848868
* Checks to make sure file does not overwrite itself if overwrite property is set to false
849869
*/
870+
@org.junit.Test
850871
public void testOverwriteFileProperty() {
851872
ISdl internalInterface = mock(ISdl.class);
852873

@@ -883,6 +904,7 @@ public void onComplete(boolean success) {
883904
* Tests overwrite property for uploading a list of files.
884905
* Checks to make sure files do not overwrite themselves if overwrite property is set to false.
885906
*/
907+
@org.junit.Test
886908
public void testOverWriteFilePropertyListFiles() {
887909
final ISdl internalInterface = mock(ISdl.class);
888910

@@ -929,6 +951,7 @@ public void onComplete(Map<String, String> errors) {
929951
/**
930952
* Test custom overridden SdlFile equals method
931953
*/
954+
@org.junit.Test
932955
public void testSdlFileEquals() {
933956
// Case 1: object is null, assertFalse
934957
SdlFile artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlArtworkTests.java

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

3-
import com.smartdevicelink.AndroidTestCase2;
3+
import android.support.test.runner.AndroidJUnit4;
4+
45
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
56
import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
67
import com.smartdevicelink.test.Test;
78

8-
public class SdlArtworkTests extends AndroidTestCase2 {
9+
import org.junit.runner.RunWith;
10+
11+
import static junit.framework.TestCase.assertEquals;
12+
import static junit.framework.TestCase.assertNotNull;
13+
import static junit.framework.TestCase.assertNotSame;
14+
import static junit.framework.TestCase.assertTrue;
15+
16+
@RunWith(AndroidJUnit4.class)
17+
public class SdlArtworkTests {
918

19+
@org.junit.Test
1020
public void testClone(){
1121
SdlArtwork original = Test.GENERAL_ARTWORK;
1222
SdlArtwork clone = original.clone();

0 commit comments

Comments
 (0)