@Test public void testCreateAdvertiseDataToManufacturerData_failedToWriteToOutput() throws Exception { int manufacturerId = DiscoveryManagerSettings.DEFAULT_MANUFACTURER_ID; int beaconAdLengthAndType = DiscoveryManagerSettings.DEFAULT_BEACON_AD_LENGTH_AND_TYPE; int mostSigBits = 1; int leastSigBits = 2; byte[] testByteArray = "bytes".getBytes(); UUID uuid = new UUID(mostSigBits, leastSigBits); int beaconAdExtraInformation = DiscoveryManagerSettings.DEFAULT_BEACON_AD_EXTRA_INFORMATION; String correctBluetoothMacAddress = "00:11:22:33:44:55"; when(mMockByteArrayOutputStream.toByteArray()).thenReturn(testByteArray); when(mMockBuilder.build()).thenReturn(mMockAdvertiseData); doThrow(IOException.class).when(mMockDataOutput).writeShort(anyByte()); AdvertiseData advertiseData = PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, uuid, beaconAdExtraInformation, correctBluetoothMacAddress, mMockBuilder, mMockByteArrayOutputStream, mMockDataOutput); verify(mMockBuilder, never()).addManufacturerData(anyInt(), any(byte[].class)); verify(mMockBuilder, never()).setIncludeDeviceName(false); verify(mMockBuilder, never()).setIncludeTxPowerLevel(false); assertThat("A null is returned in case of a failure to write to the output stream", advertiseData, is(nullValue())); }
public static AdvertiseData createAdvertiseDataToManufacturerData( int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress) { AdvertiseData.Builder builder = new AdvertiseData.Builder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(BlePeerDiscoveryUtils.ADVERTISEMENT_BYTE_COUNT); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); return PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, serviceUuid, beaconAdExtraInformation, bluetoothMacAddress, builder, byteArrayOutputStream, dataOutputStream); }
PeerAdvertisementFactory { public static AdvertiseData createAdvertiseDataToManufacturerData( int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress) { AdvertiseData.Builder builder = new AdvertiseData.Builder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(BlePeerDiscoveryUtils.ADVERTISEMENT_BYTE_COUNT); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); return PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, serviceUuid, beaconAdExtraInformation, bluetoothMacAddress, builder, byteArrayOutputStream, dataOutputStream); } }
PeerAdvertisementFactory { public static AdvertiseData createAdvertiseDataToManufacturerData( int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress) { AdvertiseData.Builder builder = new AdvertiseData.Builder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(BlePeerDiscoveryUtils.ADVERTISEMENT_BYTE_COUNT); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); return PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, serviceUuid, beaconAdExtraInformation, bluetoothMacAddress, builder, byteArrayOutputStream, dataOutputStream); }  }
PeerAdvertisementFactory { public static AdvertiseData createAdvertiseDataToManufacturerData( int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress) { AdvertiseData.Builder builder = new AdvertiseData.Builder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(BlePeerDiscoveryUtils.ADVERTISEMENT_BYTE_COUNT); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); return PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, serviceUuid, beaconAdExtraInformation, bluetoothMacAddress, builder, byteArrayOutputStream, dataOutputStream); }  static AdvertiseData createAdvertiseDataToServiceData(
            UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress); static AdvertiseData createAdvertiseDataToServiceData(
            UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress,
            AdvertiseData.Builder builder); static AdvertiseData createAdvertiseDataToManufacturerData(
            int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid,
            int beaconAdExtraInformation, String bluetoothMacAddress); static AdvertiseData createAdvertiseDataToManufacturerData(
            int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid,
            int beaconAdExtraInformation, String bluetoothMacAddress,
            AdvertiseData.Builder builder, ByteArrayOutputStream byteArrayOutputStream,
            DataOutput dataOutputStream); static PeerProperties parsedAdvertisementToPeerProperties(
            BlePeerDiscoveryUtils.ParsedAdvertisement parsedAdvertisement); static PeerProperties manufacturerDataToPeerProperties(byte[] manufacturerData, UUID serviceUuid); static UUID createProvideBluetoothMacAddressUuid(UUID serviceUuid, String requestId); static UUID generateNewProvideBluetoothMacAddressRequestUuid(UUID serviceUuid); static String parseRequestIdFromUuid(UUID provideBluetoothMacAddressRequestUuid); }
PeerAdvertisementFactory { public static AdvertiseData createAdvertiseDataToManufacturerData( int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress) { AdvertiseData.Builder builder = new AdvertiseData.Builder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(BlePeerDiscoveryUtils.ADVERTISEMENT_BYTE_COUNT); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); return PeerAdvertisementFactory.createAdvertiseDataToManufacturerData( manufacturerId, beaconAdLengthAndType, serviceUuid, beaconAdExtraInformation, bluetoothMacAddress, builder, byteArrayOutputStream, dataOutputStream); }  static AdvertiseData createAdvertiseDataToServiceData(
            UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress); static AdvertiseData createAdvertiseDataToServiceData(
            UUID serviceUuid, int beaconAdExtraInformation, String bluetoothMacAddress,
            AdvertiseData.Builder builder); static AdvertiseData createAdvertiseDataToManufacturerData(
            int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid,
            int beaconAdExtraInformation, String bluetoothMacAddress); static AdvertiseData createAdvertiseDataToManufacturerData(
            int manufacturerId, int beaconAdLengthAndType, UUID serviceUuid,
            int beaconAdExtraInformation, String bluetoothMacAddress,
            AdvertiseData.Builder builder, ByteArrayOutputStream byteArrayOutputStream,
            DataOutput dataOutputStream); static PeerProperties parsedAdvertisementToPeerProperties(
            BlePeerDiscoveryUtils.ParsedAdvertisement parsedAdvertisement); static PeerProperties manufacturerDataToPeerProperties(byte[] manufacturerData, UUID serviceUuid); static UUID createProvideBluetoothMacAddressUuid(UUID serviceUuid, String requestId); static UUID generateNewProvideBluetoothMacAddressRequestUuid(UUID serviceUuid); static String parseRequestIdFromUuid(UUID provideBluetoothMacAddressRequestUuid);  }