Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jupiter setup. #849

Merged
merged 8 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ ext {
targetCompatibilityVersion = JavaVersion.VERSION_1_8
shadowPluginVersion = '7.1.2'
daggerVersion = '2.42'
junitVersion = '5.10.2'
libs = [
/* Library-only dependencies */
rxjava2 : "io.reactivex.rxjava2:rxjava:$rxJava2Version",
rxjava3 : "io.reactivex.rxjava3:rxjava:$rxJava3Version",
rxandroid : 'io.reactivex.rxjava2:rxandroid:2.1.1',
rxrelay2 : 'com.jakewharton.rxrelay2:rxrelay:2.1.1',
rxrelay3 : 'com.jakewharton.rxrelay3:rxrelay:3.0.1',
junit : 'org.junit.jupiter:junit-jupiter:5.8.1',
junit : ["org.junit.jupiter:junit-jupiter:$junitVersion", "org.mockito:mockito-junit-jupiter:5.11.0"],
junit_platform : "org.junit:junit-bom:$junitVersion",
junit_runtime : 'org.junit.platform:junit-platform-launcher',
groovy : ['org.codehaus.groovy:groovy:3.0.9', 'org.codehaus.groovy:groovy-test:3.0.9'],
spock : 'org.spockframework:spock-core:2.0-groovy-3.0',
dagger : "com.google.dagger:dagger:$daggerVersion",
Expand Down
2 changes: 1 addition & 1 deletion gradle/src-gen-rxjava3-from-rxjava2.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generates sources compatible with RxJava 2 to RxJava 3
// copies and transforms sources compatible with RxJava 2 to RxJava 3

copy {
from "../${project.name.substring(0, project.name.length() - 1)}/src"
Expand Down
2 changes: 2 additions & 0 deletions rxandroidble/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ dependencies {

// Test dependencies
testImplementation rootProject.ext.libs.junit
testImplementation platform(rootProject.ext.libs.junit_platform)
testImplementation rootProject.ext.libs.groovy
testImplementation rootProject.ext.libs.spock
testRuntimeOnly rootProject.ext.libs.junit_runtime
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.polidea.rxandroidble2.exceptions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import android.bluetooth.BluetoothGattCharacteristic;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.UUID;

public class BleCannotSetCharacteristicNotificationExceptionTest {

@Test
public void toStringShouldContainMessage() {
// given
BluetoothGattCharacteristic mockCharacteristic = Mockito.mock(BluetoothGattCharacteristic.class);
Mockito.when(mockCharacteristic.getUuid()).thenReturn(new UUID(1, 2));
BleCannotSetCharacteristicNotificationException out = new BleCannotSetCharacteristicNotificationException(
mockCharacteristic,
BleCannotSetCharacteristicNotificationException.CANNOT_SET_LOCAL_NOTIFICATION,
new Exception("because"));

// expect
assertEquals(out.toString(),
"com.polidea.rxandroidble2.exceptions.BleCannotSetCharacteristicNotificationException: " +
"Cannot set local notification (code 1) with characteristic UUID 00000000-0000-0001-0000-000000000002");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.polidea.rxandroidble2.exceptions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class BleDisconnectedExceptionTest {

@SuppressWarnings("deprecation")
@Test
public void toStringShouldContainMessageWithUnknownStatus() {
// given
BleDisconnectedException out = new BleDisconnectedException("myBluetoothAddress");

// expect
assertEquals(out.toString(), "com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status -1 (UNKNOWN)");
}

@Test
public void toStringShouldContainMessageWithStatus() {
// given
int expectedStatus = 129; // 0x81
BleDisconnectedException out = new BleDisconnectedException("myBluetoothAddress", expectedStatus);

// expect
assertEquals(out.toString(), "com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 129 (GATT_INTERNAL_ERROR)");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.polidea.rxandroidble2.exceptions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import android.bluetooth.BluetoothGatt;

import org.junit.jupiter.api.Test;

import utils.MockUtils;

public class BleGattExceptionTest {

@Test
public void toStringShouldContainMessage() {
// given
BluetoothGatt mockBtGatt = MockUtils.bluetoothGatt("AA:BB:CC:DD:EE:FF");
BleGattException out = new BleGattException(mockBtGatt, 10, BleGattOperationType.CONNECTION_STATE);

// expect
assertEquals(out.toString(),
"com.polidea.rxandroidble2.exceptions.BleGattException: GATT exception from MAC='XX:XX:XX:XX:XX:XX', status 10 (GATT_NOT_FOUND), " +
"type BleGattOperation{description='CONNECTION_STATE'}. " +
"(Look up status 0x0a here " +
"https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h)");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.polidea.rxandroidble2.exceptions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class BleScanExceptionTest {

@Test
public void toStringShouldContainMessage() {
// given
BleScanException out = new BleScanException(BleScanException.BLUETOOTH_DISABLED);

// expect
assertEquals(out.toString(), "com.polidea.rxandroidble2.exceptions.BleScanException: Bluetooth disabled (code 1)");
}
}
17 changes: 17 additions & 0 deletions rxandroidble/src/test/java/utils/MockUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package utils;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;

import org.mockito.Mockito;

public class MockUtils {

public static BluetoothGatt bluetoothGatt(String deviceAddress) {
BluetoothGatt bluetoothGatt = Mockito.mock(BluetoothGatt.class);
BluetoothDevice bluetoothDevice = Mockito.mock(BluetoothDevice.class);
Mockito.when(bluetoothGatt.getDevice()).thenReturn(bluetoothDevice);
Mockito.when(bluetoothDevice.getAddress()).thenReturn(deviceAddress);
return bluetoothGatt;
}
}
2 changes: 2 additions & 0 deletions rxandroidble3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ dependencies {
// Test dependencies
testImplementation files(tasks.getByPath(':dagger-library-shadow:shadowJar').archiveFile)
testImplementation rootProject.ext.libs.junit
testImplementation platform(rootProject.ext.libs.junit_platform)
testImplementation rootProject.ext.libs.groovy
testImplementation rootProject.ext.libs.spock
testRuntimeOnly rootProject.ext.libs.junit_runtime
}
Loading