@Test
public void devicesAreCleanedWhenTheNetworkAddressIsNotAllowedToHaveDuplicates() throws Exception {

    this.withConfigurationNotAllowingDuplicates();
    this.withHostAndInetAddress(IP_ADDRESS);
    this.theNetworkAddressIsUsedBy(this.inetAddress, "device1", "device2");
    this.deviceNetworkAddressCleanupService.clearDuplicateAddresses(DEVICE_IDENTIFICATION, this.host);
    verify(this.deviceRepository, times(1)).findByNetworkAddress(this.inetAddress);
    final ArgumentCaptor<Device> deviceCaptor = ArgumentCaptor.forClass(Device.class);
    verify(this.deviceRepository, times(2)).save(deviceCaptor.capture());
    final List<Device> savedDevices = deviceCaptor.getAllValues();
    this.deviceIsSavedWithCleanedNetworkAddress("device1", savedDevices);
    this.deviceIsSavedWithCleanedNetworkAddress("device2", savedDevices);
}