DeviceConverter extends BidirectionalConverter<SmartMeteringDeviceDto, DlmsDevice> { @Override public DlmsDevice convertTo(final SmartMeteringDeviceDto source, final Type<DlmsDevice> destinationType, final MappingContext context) { final DlmsDevice dlmsDevice = new DlmsDevice(); dlmsDevice.setDeviceIdentification(source.getDeviceIdentification()); dlmsDevice.setCommunicationMethod(source.getCommunicationMethod()); dlmsDevice.setCommunicationProvider(source.getCommunicationProvider()); dlmsDevice.setIccId(source.getICCId()); dlmsDevice.setHls3Active(source.isHLS3Active()); dlmsDevice.setHls4Active(source.isHLS4Active()); dlmsDevice.setHls5Active(source.isHLS5Active()); dlmsDevice.setMbusIdentificationNumber(source.getMbusIdentificationNumber()); dlmsDevice.setMbusManufacturerIdentification(source.getMbusManufacturerIdentification()); dlmsDevice.setProtocol(source.getProtocolName(), source.getProtocolVersion()); if (source.getMasterKey() != null) { dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_MASTER, Hex.encodeHexString(source.getMasterKey()), source.getDeliveryDate(), null)); } if (source.getAuthenticationKey() != null) { dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_AUTHENTICATION, Hex.encodeHexString(source.getAuthenticationKey()), source.getDeliveryDate(), null)); } if (source.getGlobalEncryptionUnicastKey() != null) { dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.E_METER_ENCRYPTION, Hex.encodeHexString(source.getGlobalEncryptionUnicastKey()), source.getDeliveryDate(), null)); } if (source.getMbusDefaultKey() != null) { dlmsDevice.addSecurityKey(new SecurityKey(dlmsDevice, SecurityKeyType.G_METER_MASTER, Hex.encodeHexString(source.getMbusDefaultKey()), source.getDeliveryDate(), null)); } return dlmsDevice; }  @Override DlmsDevice convertTo(final SmartMeteringDeviceDto source, final Type<DlmsDevice> destinationType,
            final MappingContext context); @Override SmartMeteringDeviceDto convertFrom(final DlmsDevice source,
            final Type<SmartMeteringDeviceDto> destinationType, final MappingContext context);  }
@Test public void convertsSmartMeteringDtoToDlmsDevice() { final SmartMeteringDeviceDto dto = new SmartMeteringDeviceDtoBuilder().build(); final DlmsDevice result = this.converter.convertTo(dto, null, null); final DlmsDevice expected = this.converted(dto); Assertions.assertThat(result) .isEqualToIgnoringGivenFields(expected, "creationTime", "modificationTime", "version"); Assertions.assertThat(result.getSecurityKeys()) .usingElementComparatorIgnoringFields("creationTime", "modificationTime", "version") .isEqualTo(expected.getSecurityKeys()); }