summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/transport/TransportTypeTests.java
blob: dc54b21976c29dd75a5d756a42fd1f9c3c0457ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.smartdevicelink.test.transport;

import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.transport.enums.TransportType;

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This is a unit test class for the SmartDeviceLink library project class : 
 * {@link com.smartdevicelink.transport.enums.TransportType}
 */
public class TransportTypeTests extends TestCase {
	
	/**
	 * This is a unit test for the following enum : 
	 * {@link com.smartdevicelink.transport.enums.TransportType}
	 */
	public void testTransportTypeEnum () {
		
		// Test Values
		String testTcp       		= "TCP";
		String testUsb       		= "USB";
		String testInvalid   		= "INVALID";
		String testBluetooth 		= "BLUETOOTH";
		String testMultiplexing 	= "MULTIPLEX";
		String testWebSocketServer 	= "WEB_SOCKET_SERVER";
		String testCustom 			= "CUSTOM";

		try {
			// Comparison Values
			TransportType expectedTcpEnum        		= TransportType.TCP;
			TransportType expectedUsbEnum        		= TransportType.USB;
			TransportType expectedBluetoothEnum  		= TransportType.BLUETOOTH;
			TransportType expectedMultiplexingEnum  	= TransportType.MULTIPLEX;
			TransportType expectedWebSocketServerEnum  	= TransportType.WEB_SOCKET_SERVER;
			TransportType expectedCustomEnum  			= TransportType.CUSTOM;

			List<TransportType> expectedEnumList = new ArrayList<TransportType>();
			expectedEnumList.add(TransportType.BLUETOOTH);
			expectedEnumList.add(TransportType.TCP);
			expectedEnumList.add(TransportType.USB);
			expectedEnumList.add(TransportType.MULTIPLEX);
			expectedEnumList.add(TransportType.WEB_SOCKET_SERVER);
			expectedEnumList.add(TransportType.CUSTOM);

			TransportType actualNullEnum       			= TransportType.valueForString(null);
			TransportType actualTcpEnum        			= TransportType.valueForString(testTcp);
			TransportType actualUsbEnum        			= TransportType.valueForString(testUsb);
			TransportType actualInvalidEnum    			= TransportType.valueForString(testInvalid);
			TransportType actualBluetoothEnum  			= TransportType.valueForString(testBluetooth);
			TransportType actualMultiplexingEnum 		= TransportType.valueForString(testMultiplexing);
			TransportType actualWebSocketServerEnum 	= TransportType.valueForString(testWebSocketServer);
			TransportType actualCustomEnum			 	= TransportType.valueForString(testCustom);

			List<TransportType> actualEnumList = Arrays.asList(TransportType.values());
			
			// Valid Tests
			assertEquals(TestValues.MATCH, expectedTcpEnum, actualTcpEnum);
			assertEquals(TestValues.MATCH, expectedUsbEnum, actualUsbEnum);
			assertEquals(TestValues.MATCH, expectedBluetoothEnum, actualBluetoothEnum);
			assertEquals(TestValues.MATCH, expectedMultiplexingEnum, actualMultiplexingEnum);
			assertEquals(TestValues.MATCH, expectedWebSocketServerEnum, actualWebSocketServerEnum);
			assertEquals(TestValues.MATCH, expectedCustomEnum, actualCustomEnum);
			assertTrue(TestValues.ARRAY, expectedEnumList.containsAll(actualEnumList) && actualEnumList.containsAll(expectedEnumList));
			
			// Invalid/Null Tests
			assertNull(TestValues.NULL, actualInvalidEnum);
			assertNull(TestValues.NULL, actualNullEnum);
		
		} catch (NullPointerException e) {
			fail("Could not retrieve value for null string, should return null.");
		} catch (IllegalArgumentException e) {
			fail("Could not retrieve value for invalid string, should return null.");
		}
	}
}