Skip to content

Commit

Permalink
android sdk and sources updated to rx3
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkki Silvola committed Apr 20, 2020
1 parent 79c84fa commit 3d0f413
Show file tree
Hide file tree
Showing 41 changed files with 1,832 additions and 3,289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ android {
dexOptions {
javaMaxHeapSize "2g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand All @@ -31,9 +35,9 @@ dependencies {
implementation files('libs/polar-ble-sdk.aar')
implementation files('libs/polar-protobuf-release.aar')
implementation 'com.google.protobuf:protobuf-java:3.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
Expand Down

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions sources/Android/android-communications/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ buildscript {
}

android {
compileSdkVersion 27
compileSdkVersion 29
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 21
targetSdkVersion 27
targetSdkVersion 29
versionCode 13
versionName "13"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes.all { buildType ->
def version = getVersion()
Expand All @@ -79,6 +80,10 @@ android {
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

if ( project.hasProperty("artifactoryUser") && project.hasProperty("artifactoryPassword") ) {
Expand Down Expand Up @@ -163,11 +168,13 @@ dependencies {
implementation project(':polar-protobuf')
implementation 'com.google.protobuf:protobuf-java:3.1.0'
}
testImplementation 'junit:junit:4.12'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:3.2.4"
testImplementation "io.mockk:mockk:1.9.3"
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
implementation 'commons-io:commons-io:2.4'
implementation 'com.android.support:support-annotations:24.2.1'
implementation 'com.android.support:support-annotations:28.0.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package com.androidcommunications.polar

import android.content.Context
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import com.androidcommunications.polar.api.ble.model.BleDeviceSession
import com.androidcommunications.polar.enpoints.ble.bluedroid.host.BDDeviceSessionImpl
import com.androidcommunications.polar.enpoints.ble.bluedroid.host.connection.ConnectionHandler
import com.androidcommunications.polar.enpoints.ble.bluedroid.host.connection.ConnectionHandlerObserver
import com.androidcommunications.polar.enpoints.ble.bluedroid.host.connection.ConnectionInterface
import com.androidcommunications.polar.enpoints.ble.bluedroid.host.connection.ScannerInterface
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import io.mockk.impl.annotations.MockK
import junit.framework.TestCase

@RunWith(AndroidJUnit4::class)
class InstrumentedTests {

private lateinit var targetContext: Context
private lateinit var connectionHandler: ConnectionHandler

@MockK
private lateinit var connectionInterface: ConnectionInterface

@MockK
private lateinit var scannerInterface: ScannerInterface

@MockK
private lateinit var connectionHandlerObserver: ConnectionHandlerObserver

@Before
fun setUp() {
targetContext = InstrumentationRegistry.getInstrumentation().targetContext
connectionHandler = ConnectionHandler(targetContext, connectionInterface, scannerInterface, connectionHandlerObserver)
}

@Test
fun testConnectionHandler_1() {
val bleDeviceSession = BDDeviceSessionImpl()
connectionHandler.connectDevice(bleDeviceSession, true)
connectionHandler.deviceConnected(bleDeviceSession)
TestCase.assertSame(bleDeviceSession.sessionState, BleDeviceSession.DeviceSessionState.SESSION_OPEN)
}

@Test
fun testConnectionHandler_2() {
val bleDeviceSession = BDDeviceSessionImpl()
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceDisconnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.advertisementHeadReceived(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceConnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
}

@Test
fun testConnectionHandler_3() {
val bleDeviceSession = BDDeviceSessionImpl()
val bleDeviceSession2 = BDDeviceSessionImpl()

// multi connections
connectionHandler.connectDevice(bleDeviceSession, true);
connectionHandler.connectDevice(bleDeviceSession2, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.deviceConnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.advertisementHeadReceived(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceConnected(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);

// multi disconnection
connectionHandler.disconnectDevice(bleDeviceSession);
connectionHandler.disconnectDevice(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.deviceDisconnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.deviceDisconnected(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED);

// multi connect / disconnect
bleDeviceSession2.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.connectDevice(bleDeviceSession, true);
connectionHandler.disconnectDevice(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.deviceConnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.deviceDisconnected(bleDeviceSession2);

// maintaining multi connections
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
bleDeviceSession2.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.deviceDisconnected(bleDeviceSession);
connectionHandler.deviceDisconnected(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.advertisementHeadReceived(bleDeviceSession);
connectionHandler.advertisementHeadReceived(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.deviceConnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.advertisementHeadReceived(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceConnected(bleDeviceSession2);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
TestCase.assertSame(bleDeviceSession2.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);

// same state tests
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceConnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN);

bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
connectionHandler.disconnectDevice(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.disconnectDevice(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.disconnectDevice(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.deviceDisconnected(bleDeviceSession);

//
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
// TODO nonConnectable[0] = true;
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.advertisementHeadReceived(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
// TODO nonConnectable[0] = false;
connectionHandler.advertisementHeadReceived(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPENING);
connectionHandler.deviceConnected(bleDeviceSession);

//
connectionHandler.disconnectDevice(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSING);
connectionHandler.connectDevice(bleDeviceSession, true);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
connectionHandler.deviceDisconnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);

bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
connectionHandler.connectDevice(bleDeviceSession, false);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);

bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.setAutomaticReconnection(false);
connectionHandler.deviceDisconnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
bleDeviceSession.setSessionState(BleDeviceSession.DeviceSessionState.SESSION_OPEN);
connectionHandler.setAutomaticReconnection(true);
connectionHandler.deviceDisconnected(bleDeviceSession);
TestCase.assertSame(bleDeviceSession.getSessionState(), BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
}
}
Loading

0 comments on commit 3d0f413

Please sign in to comment.