private void verifyCommandFail() { CommandResult result = CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE); verify(commandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); verify(operationCommandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); } }
@Test public void testSetLatestModificationTime() { holder.addPropertyChangeListener(listener); holder.setLatestModificationTime(TIMESTAMP1); holder.setLatestModificationTime(TIMESTAMP2); final InOrder inOrder = inOrder(listener); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "latestModificationTime", null, TIMESTAMP1))); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "latestModificationTime", TIMESTAMP1, TIMESTAMP2))); verifyNoMoreInteractions(listener); }
@Test public void testOnCharacteristicRead() { BluetoothGattCharacteristic otherCharacteristic = Mockito.mock(BluetoothGattCharacteristic.class); when(otherCharacteristic.getUuid()).thenReturn(Neatle.createUUID(123)); when(gatt.getService(eq(serviceUUID))).thenReturn(gattService); when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic); when(gatt.readCharacteristic(eq(gattCharacteristic))).thenReturn(true); when(gattCharacteristic.getValue()).thenReturn(new byte[]{21, 22}); when(gattCharacteristic.getUuid()).thenReturn(characteristicUUID); readCommand.execute(device, operationCommandObserver, gatt); // Unknown characteristic readCommand.onCharacteristicRead(gatt, otherCharacteristic, BluetoothGatt.GATT_SUCCESS); verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class)); verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class)); Mockito.reset(commandObserver, operationCommandObserver); // Known characteristic readCommand.onCharacteristicRead(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS); CommandResult result = CommandResult.createCharacteristicRead(gattCharacteristic, BluetoothGatt.GATT_SUCCESS); verify(commandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); verify(operationCommandObserver, times(1)).finished(eq(readCommand), refEq(result, "timestamp")); }
@Test public void testBeanIsAvailableChange() { stub(bean.isAvailable()).toReturn(false); holder.addPropertyChangeListener(listener); final TimestampProviderMock timestampProvider = (TimestampProviderMock)TimestampProvider.Locator.findTimestampProvider(); // Test a bean property change that makes bean.isAvailable() to transition from false to true timestampProvider.setTimestamp(TIMESTAMP1); assertFalse(bean.isAvailable()); stub(bean.isAvailable()).toReturn(true); holder.propertyChangeListener.propertyChange(new MyPropertyChangeEvent(bean, "stringProperty", null, "newValue")); // Test a bean property change that makes bean.isAvailable() to transition from true to false timestampProvider.setTimestamp(TIMESTAMP2); assertTrue(bean.isAvailable()); stub(bean.isAvailable()).toReturn(false); holder.propertyChangeListener.propertyChange(new MyPropertyChangeEvent(bean, "stringProperty", "newValue", null)); // Test a bean property change that makes bean.isAvailable() to stay false timestampProvider.setTimestamp(TIMESTAMP3); assertFalse(bean.isAvailable()); holder.propertyChangeListener.propertyChange(new MyPropertyChangeEvent(bean, "stringProperty", null, null)); final InOrder inOrder = inOrder(listener); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "latestModificationTime", null, TIMESTAMP1))); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "available", false, true))); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "latestModificationTime", TIMESTAMP1, TIMESTAMP2))); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "available", true, false))); inOrder.verify(listener).propertyChange(refEq(new MyPropertyChangeEvent(holder, "latestModificationTime", TIMESTAMP2, TIMESTAMP3))); verifyNoMoreInteractions(listener); } }