Git Product home page Git Product logo

Comments (8)

uKL avatar uKL commented on May 18, 2024

I did quick test for this issue

 def "should return filtered BluetoothDevice"() {
        given:
        def serviceUUID = UUID.fromString("00001234-0000-0000-8000-000000000000")
        def rxBleClient = new RxBleClientMock.Builder()
                .addDevice(
                new RxBleClientMock.DeviceBuilder()
                        .deviceMacAddress("AA:BB:CC:DD:EE:FF")
                        .deviceName("TestDevice")
                        .scanRecord("some scan record bytes".getBytes())
                        .rssi(42)
                        .addService(serviceUUID, emptyList()
                ).build()
        ).build();
        def testSubscriber = TestSubscriber.create()

        when:
        rxBleClient.scanBleDevices(serviceUUID)
                .take(1)
                .map { scanResult -> scanResult.getBleDevice().getMacAddress() }
                .subscribe(testSubscriber)

        then:
        testSubscriber.assertValue("AA:BB:CC:DD:EE:FF")
    }

Am I missing something?

  1. Added service does not affect advertisement payload in the mock
  2. Advertisement payload is somewhat transparent for mock but required (see above)
  3. Mock supports filtering.

Could you provide a code snippet with your mock?

from rxandroidble.

pfives avatar pfives commented on May 18, 2024

Thanks for the quick response @uKL. Here's some code:

static final String DEVICE_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF";
static final UUID AD_UUID = UUID.fromString("cd336c84-0b2f-1136-b512-3e1d05defe78");
static final String DEVICE_NAME = "test1236";
static final int RSSI = 42;

RxBleDevice rxBleDevice = new RxBleClientMock.DeviceBuilder().deviceMacAddress(DEVICE_MAC_ADDRESS)
                .deviceName(DEVICE_NAME).rssi(RSSI).scanRecord(getScanRecord()).addService(AD_UUID, Collections.emptyList()).build();

RxBleClient rxBleClient = new RxBleClientMock.Builder().addDevice(rxBleDevice).build();

TestSubscriber<RxBleScanResult> testSubscriber = new TestSubscriber<>();

//test passes with this call
rxBleClient.scanBleDevices().subscribe(testSubscriber);

//THIS test will fail
//rxBleClient.scanBleDevices(AD_UUID).subscribe(testSubscriber)

List<RxBleScanResult> rxBleScanResults = testSubscriber.getOnNextEvents();
Assert.assertTrue(rxBleScanResults.size() == 1);

from rxandroidble.

uKL avatar uKL commented on May 18, 2024

Ok, fun fact. Mock was not released to central yet (strange, we will do a release soon then @dariuszseweryn gets back from WWDC).

How did you build mocking support? It looks like we had this issue in earlier version but in master it should be fixed already.

from rxandroidble.

pfives avatar pfives commented on May 18, 2024

Shoot my bad. I just grabbed the files directly from the repo because I couldn't get them from the gradle script (eventually saw this issue #20). I am using these 3 files located here: https://github.com/Polidea/RxAndroidBle/tree/master/mockrxandroidble/src/main/java/com/polidea/rxandroidble/mockrxandroidble

Is there maybe a newer branch than master with mock class updates on it?

from rxandroidble.

uKL avatar uKL commented on May 18, 2024

Master is the newest one and it should work. Those three files is everything you need.

I ran your test and guess what... it's passing :) What's in your getScanRecord() method?

from rxandroidble.

pfives avatar pfives commented on May 18, 2024

It was a method that returned a specific byte[] that mimicked an actual scan record from a device. I replaced it with "some scan record bytes".getBytes() and still have the same issue. Passes with no UUID specified but fails when using one. When you ran the above it passed in both situations (using the commented out line)?

I noticed there were some updates on the mock-indications branch that are newer than master, could those be helpful?

from rxandroidble.

mzgreen avatar mzgreen commented on May 18, 2024

@pfives I'm not able to reproduce this issue. I tried to run your sample and both calls:

rxBleClient.scanBleDevices().subscribe(testSubscriber);
and
rxBleClient.scanBleDevices(AD_UUID).subscribe(testSubscriber);

return correct value. Please recheck if you can reproduce the issue in the newest version of the library.

from rxandroidble.

dariuszseweryn avatar dariuszseweryn commented on May 18, 2024

Since the issue was not reproducible by @mzgreen and there is no other information. I am closing this.

from rxandroidble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.