### Question:
DeviceRegisterImpl implements DeviceRegister { @Override public Device saveOrUpdateDevice(final DeviceInfoReport report) { String deviceName = report.getNetworkInfo().getHostname(); return registerDeviceToManager(deviceName, report); } @Autowired  DeviceRegisterImpl(final DeviceManager deviceManager,
                              final DeviceGroupManager deviceGroupManager); @Override Device saveOrUpdateDevice(final DeviceInfoReport report); @Override Device saveOrUpdateDevice(final String deviceName);  }### Answer:
@Test public void registerNonStoredDeviceByReport() { final DeviceManager deviceManager = mock(DeviceManager.class); final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class); final InetAddress ipAddress = getTestIpAddress(); final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS); final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(), new FirmwareInfo(), new HardwareInfo(), new TPMInfo()); final DeviceGroup group = new DeviceGroup("test"); when(deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP)).thenReturn(group); DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager); register.saveOrUpdateDevice(report); verify(deviceManager).saveDevice(any(Device.class)); }
@Test public void registerNonStoredDeviceByName() { final DeviceManager deviceManager = mock(DeviceManager.class); final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class); final DeviceGroup group = new DeviceGroup("test"); when(deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP)).thenReturn(group); DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager); register.saveOrUpdateDevice(HOSTNAME); verify(deviceManager).saveDevice(any(Device.class)); }
@Test public void registerExistingDeviceByReport() { final DeviceManager deviceManager = mock(DeviceManager.class); final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class); final InetAddress ipAddress = getTestIpAddress(); final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS); final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(), new FirmwareInfo(), new HardwareInfo(), new TPMInfo()); final Device device = new Device(HOSTNAME); when(deviceManager.getDevice(HOSTNAME)).thenReturn(device); DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager); register.saveOrUpdateDevice(report); verify(deviceManager).updateDevice(any(Device.class)); }
@Test public void registerExistingDeviceByName() { final DeviceManager deviceManager = mock(DeviceManager.class); final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class); final Device device = new Device(HOSTNAME); when(deviceManager.getDevice(HOSTNAME)).thenReturn(device); DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager); register.saveOrUpdateDevice(HOSTNAME); verify(deviceManager).updateDevice(any(Device.class)); }