### Question:
ForceRemoveRequestHandler extends AbstractRemoveRequestHandler { @Override public MessageBody handleMessage(PlatformMessage message) throws Exception { logger.debug("received a force remove device request: {}", message); Device device = loadDevice(message); if(device.isLost()) { service.delete(device); } else { try { sendRemoveRequest(device, 0L, true); } catch(Exception e) { logger.warn("Unable to cleanly remove device {}", message.getSource()); } service.tombstone(device); } return ForceRemoveResponse.instance(); } @Inject  ForceRemoveRequestHandler(
         DeviceDAO deviceDao,
         PlatformMessageBus platformBus,
         Set<GroovyDriverPlugin> plugins,
         DeviceService service
   ); @Override String getMessageType(); @Override MessageBody handleMessage(PlatformMessage message);  }### Answer:
@Test public void testForceRemoveActiveDevice() throws Exception { device.setState(Device.STATE_ACTIVE_SUPPORTED); EasyMock.expect(deviceDao.findById(device.getId())).andReturn(device); service.tombstone(device); EasyMock.expectLastCall(); replay(); MessageBody response = handler.handleMessage(createRemoveRequest()); assertEquals(ForceRemoveResponse.instance(), response); PlatformMessage message = platformBus.take(); assertDeviceRemovedMessage(device, message); assertNull(platformBus.poll()); verify(); }
@Test public void testForceRemoveMissingDevice() throws Exception { EasyMock.expect(deviceDao.findById(device.getId())).andReturn(null); replay(); try { handler.handleMessage(createRemoveRequest()); fail(); } catch(NotFoundException e) { } assertNull(platformBus.poll()); verify(); }
@Test public void testForceRemoveLostDevice() throws Exception { device.setState(Device.STATE_LOST_RECOVERABLE); EasyMock.expect(deviceDao.findById(device.getId())).andReturn(device); EasyMock.expect(service.delete(device)).andReturn(true); replay(); MessageBody response = handler.handleMessage(createRemoveRequest()); assertEquals(ForceRemoveResponse.instance(), response); assertNull(platformBus.poll()); verify(); }
@Test public void testForceRemoveTombstonedDevice() throws Exception { device.setState(Device.STATE_TOMBSTONED); EasyMock.expect(deviceDao.findById(device.getId())).andReturn(device); service.tombstone(device); EasyMock.expectLastCall(); replay(); MessageBody response = handler.handleMessage(createRemoveRequest()); assertEquals(ForceRemoveResponse.instance(), response); PlatformMessage message = platformBus.take(); assertDeviceRemovedMessage(device, message); assertNull(platformBus.poll()); verify(); }