### Question:
DBIMADeviceStateManager extends DBDeviceStateManager implements IMADeviceStateManager { @Override public final IMADeviceState saveState(final IMADeviceState state) throws IMADeviceStateManagerException { try { return (IMADeviceState) super.saveState(state); } catch (DeviceStateManagerException e) { throw new IMADeviceStateManagerException(e); } } DBIMADeviceStateManager(final SessionFactory factory); @Override final IMADeviceState saveState(final IMADeviceState state); @Override final IMADeviceState getState(final Device device); @Override final void updateState(final IMADeviceState state); @Override final boolean deleteState(final Device device);  }### Answer:
@Test public void testSaveDefaultState() { Assert.assertEquals(DBUtility.getCount(sessionFactory, IMADeviceState.class), 0); final IMADeviceState state = new IMADeviceState(device); final IMADeviceState savedState = stateManager.saveState(state); Assert.assertEquals(DBUtility.getCount(sessionFactory, IMADeviceState.class), 1); Assert.assertEquals(savedState, state); }
@Test public void testSaveState() { Assert.assertEquals(DBUtility.getCount(sessionFactory, IMADeviceState.class), 0); final IMADeviceState state = new IMADeviceState(device); updateState(state); final IMADeviceState savedState = stateManager.saveState(state); Assert.assertEquals(DBUtility.getCount(sessionFactory, IMADeviceState.class), 1); Assert.assertEquals(savedState, state); }
@Test(expectedExceptions = IMADeviceStateManagerException.class) public void testSaveWithSameDevice() { final IMADeviceState state = new IMADeviceState(device); final IMADeviceState state2 = new IMADeviceState(device); stateManager.saveState(state); stateManager.saveState(state2); Assert.fail("second save did not fail"); }
@Test(expectedExceptions = NullPointerException.class) public void testSaveNullState() { stateManager.saveState(null); }