From 73179f238aeaa5b74ced73d07eeed2b486ac408f Mon Sep 17 00:00:00 2001 From: Dariusz Seweryn Date: Sun, 17 Mar 2024 11:28:09 +0100 Subject: [PATCH] Migrated BleDisconnectedExceptionTest. --- .../BleDisconnectedExceptionTest.groovy | 33 ------------------- .../BleDisconnectedExceptionTest.java | 28 ++++++++++++++++ 2 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 rxandroidble/src/test/groovy/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.groovy create mode 100644 rxandroidble/src/test/java/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.java diff --git a/rxandroidble/src/test/groovy/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.groovy b/rxandroidble/src/test/groovy/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.groovy deleted file mode 100644 index ffec7becf..000000000 --- a/rxandroidble/src/test/groovy/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.groovy +++ /dev/null @@ -1,33 +0,0 @@ -package com.polidea.rxandroidble2.exceptions - -import spock.lang.Specification - -/** - * Created by jallen on 2017-11-01. - */ -class BleDisconnectedExceptionTest extends Specification { - - BleDisconnectedException objectUnderTest - - def "toString should include message with unknown status"() { - - when: - objectUnderTest = new BleDisconnectedException("myBluetoothAddress") - - then: - assert objectUnderTest.toString() == - "com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status -1 (UNKNOWN)" - } - - def "toString should include message with status"() { - given: - def expectedStatus = 0x81 - - when: - objectUnderTest = new BleDisconnectedException("myBluetoothAddress", expectedStatus) - - then: - assert objectUnderTest.toString() == - "com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status $expectedStatus (GATT_INTERNAL_ERROR)" - } -} diff --git a/rxandroidble/src/test/java/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.java b/rxandroidble/src/test/java/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.java new file mode 100644 index 000000000..442432720 --- /dev/null +++ b/rxandroidble/src/test/java/com/polidea/rxandroidble2/exceptions/BleDisconnectedExceptionTest.java @@ -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)"); + } +}