summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java
blob: d9af0faed028c299bebf71d0ee21d03f7aebc553 (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
package com.smartdevicelink.transport;

import android.os.Looper;
import android.os.Messenger;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.smartdevicelink.transport.enums.TransportType;

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.
 */
@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) {
            Looper.prepare();
        }

        // Instantiate SdlRouterService and Registered App class
        SdlRouterService router = new SdlRouterService();
        SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, 1, messenger);

        // Call Handle Message
        app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START,bytes, TransportType.BLUETOOTH);

        // Insure that the buffer is not null, if it is the test will fail
        assertNotNull(app.buffer);


    }

    @Test
    public void testNullBuffer() {

        if (Looper.myLooper() == null) {
            Looper.prepare();
        }

        // Instantiate SdlRouterService and Registered App class
        SdlRouterService router = new SdlRouterService();
        SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, 1, messenger);

        // Force Null Buffer
        app.buffer = null;

        // Call Handle Message - Making sure it doesn't init buffer
        app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_NONE, bytes, TransportType.BLUETOOTH);

        // Insure that the buffer is null. and no NPE
        assertNull(app.buffer);

    }
}