DeviceDaoImpl implements DeviceDao { @Override public boolean removeDevice(final String deviceId) { Device device = devices.get(deviceId); if (device != null) { device.close(); devices.remove(deviceId); return true; } return false; } DeviceDaoImpl(); @Override void addDevice(final Device device); @Override boolean removeDevice(final String deviceId); @Override Device getDevice(final String deviceId); @Override Collection<Device> getDevices(); @Override Collection<Device> findDevices(final String hostAddress);  }
@Test public void testRemoveDevice() throws UnknownDeviceException { Device device = createMock(Device.class); expect(device.getId()).andReturn("deviceId"); device.close(); expectLastCall(); replay(device); DeviceDaoImpl deviceDao = new DeviceDaoImpl(); deviceDao.addDevice(device); boolean removed = deviceDao.removeDevice("deviceId"); assertTrue(removed); assertEquals(0, deviceDao.getDevices().size()); verify(device); }