### Question:
DBDeviceManager extends DBManager<Device> implements
        DeviceManager { @Override public final Device saveDevice(final Device device) throws DeviceManagerException { LOGGER.debug("saving device: {}", device); try { return super.save(device); } catch (DBManagerException e) { throw new DeviceManagerException(e); } } DBDeviceManager(final SessionFactory sessionFactory); @Override final Device saveDevice(final Device device); @Override final void updateDevice(final Device device); @Override final void updateDeviceList(final Set<Device> deviceList); @Override final Set<Device> getDeviceList(); @Override final List<String> getDeviceNameList(); @Override final FilteredRecordsList<Device> getOrderedDeviceList(
            final String columnToOrder, final boolean ascending, final int firstResult,
            final int maxResults, final String search); @Override final Device getDevice(final String name); @Override final List<Device> getDefaultDevices(); @Override final boolean deleteDevice(final String name);  }### Answer:
@Test public void testSave() throws Exception { LOGGER.debug("testSave test started"); Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0); Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 0); final Device device = DeviceTest.getTestDevice(deviceName); final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP); device.setDeviceGroup(group); final DeviceManager mgr = new DBDeviceManager(sessionFactory); final Device d2 = mgr.saveDevice(device); Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1); Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 1); Assert.assertEquals(d2, device); Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, deviceName)); final UUID reportId = d2.getDeviceInfo().getId(); Assert.assertNotNull(reportId); Assert.assertTrue( DBUtility.isInDatabase(sessionFactory, DeviceInfoReport.class, "id", reportId) ); }
@Test(expectedExceptions = DeviceManagerException.class) public void testSaveTwice() throws DeviceManagerException, Exception { LOGGER.debug("testSaveTwice test started"); final Device device = new Device(deviceName); final DeviceManager mgr = new DBDeviceManager(sessionFactory); final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP); device.setDeviceGroup(group); final Device b2 = mgr.saveDevice(device); mgr.saveDevice(b2); Assert.fail("second save did not fail"); }
@Test(expectedExceptions = DeviceManagerException.class) public void testSaveSameName() throws DeviceManagerException { LOGGER.debug("testSaveSameName test started"); final Device device = new Device(deviceName); final Device device2 = new Device(deviceName); final DeviceManager mgr = new DBDeviceManager(sessionFactory); final Device b2 = mgr.saveDevice(device); Assert.assertNotNull(b2); mgr.saveDevice(device2); Assert.fail("second save did not fail"); }
@Test(expectedExceptions = NullPointerException.class) public void testSaveNullDevice() throws DeviceManagerException { LOGGER.debug("testSaveNullDevice test started"); final DeviceManager mgr = new DBDeviceManager(sessionFactory); mgr.saveDevice(null); Assert.fail("save did not fail"); }