DeviceManagerImpl implements DeviceManager { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class}) public List<Device> getAllDevices() { List<Device> allDevices = m_deviceDao.findAllDevices(); return allDevices; } 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 testGetAllDevice() { Device deviceA = createDevice("deviceA"); Device deviceB = createDevice("deviceA"); List<Device> deviceList = new ArrayList<>(); deviceList.add(deviceA); deviceList.add(deviceB); when(m_deviceDao.findAllDevices()).thenReturn(deviceList); List<Device> devices = m_dm.getAllDevices(); verify(m_deviceDao).findAllDevices(); assertEquals(deviceList, devices); }
@Test public void testGetAllDeviceNull() { verify(m_deviceDao, never()).findAllDevices(); List<Device> deviceList = m_dm.getAllDevices(); verify(m_deviceDao).findAllDevices(); assertEquals(0, deviceList.size()); }