I'm bringing up Bluetooth support on Android. Under test, I'd like to set a fake
android.bluetooth.BluetoothAdapter, which would return a tree of related fake objects (BluetoothLeScanner, ScanResult, BluetoothDevice, BluetoothGatt, BluetoothGattService, BluetoothGattCharacteristic, ...)
BluetoothAdapter, BluetoothLeScanner, BluetoothGatt are a final classes. I'm new to Java, but so far my research shows this adds a hurdle to testing that can be overcome by:
+ Wrapping all calls to the AndroidSDK objects with an interface I define, passing through in the default implementation or returning fake results/objects in a test implementation. Due to the nested final classes, the wrappers will return wrappers (or alternatively flatten the object hierarchy a bit). The obvious downside is diluting the codebase with low value indirection.
+ Using a mocking tool such as
PowerMock to create fake objects. (
Doc on final classes) Code to create fakes is much simpler, but I don't believe we have any solution available yet that can fake final classes.
I have yet to find chromium code that fakes Android objects -- please point me to examples if you know them.
Know of another solution? I'd love to hear it.
Unless there's consensus that we should really consider adding e.g. PowerMock to chromium then I'll go down the wrapping route.