DeviceManagerImpl implements DeviceManager { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class}) public Device getDevice(String deviceName) { Device device = m_deviceDao.getDeviceByName(deviceName); if (device == null) { throw new IllegalArgumentException("Device " + deviceName + " does not exist"); } return device; } DeviceManagerImpl(DeviceDao deviceDao); void setDeviceDao(DeviceDao deviceDao); @Override void deviceAdded(String deviceName); @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class}) Device getDevice(String deviceName); @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Device> getAllDevices(); @Override void deviceRemoved(String deviceName); @Override void devicePropertyChanged(String deviceName); @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class}) void updateConfigAlignmentState(String deviceName, String verdict); @Override void removeDeviceStateProvider(DeviceStateProvider stateProvider); @Override void addDeviceStateProvider(DeviceStateProvider stateProvider);  }
@Test public void testGetDevice() { Device deviceA = createDevice("deviceA"); when(m_deviceDao.getDeviceByName("deviceA")).thenReturn(deviceA); Device device = m_dm.getDevice("deviceA"); verify(m_deviceDao).getDeviceByName("deviceA"); assertEquals(deviceA, device); }
@Test public void testGetDeviceNull() { try { m_dm.getDevice("deviceA"); verify(m_deviceDao).getDeviceByName("deviceA"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { assertEquals("Device deviceA does not exist", e.getMessage()); } }
@Test public void testDeviceMetaIsFetchedFromDMS() { Device device = mock(Device.class); when(m_deviceDao.getDeviceByName("Bangalore-south")).thenReturn(device); assertEquals(device, m_dm.getDevice("Bangalore-south")); verify(m_deviceDao).getDeviceByName("Bangalore-south"); }