SystemFlagsDeployResult { WireSystemFlagsDeployResult toWire() { var wireResult = new WireSystemFlagsDeployResult(); wireResult.changes = new ArrayList<>(); for (FlagDataChange change : flagChanges) { var wireChange = new WireFlagDataChange(); wireChange.flagId = change.flagId().toString(); wireChange.operation = change.operation().asString(); wireChange.targets = change.targets().stream().map(FlagsTarget::asString).collect(toList()); wireChange.data = change.data().map(FlagData::toWire).orElse(null); wireChange.previousData = change.previousData().map(FlagData::toWire).orElse(null); wireResult.changes.add(wireChange); } wireResult.errors = new ArrayList<>(); for (OperationError error : errors) { var wireError = new WireOperationFailure(); wireError.message = error.message(); wireError.operation = error.operation().asString(); wireError.targets = error.targets().stream().map(FlagsTarget::asString).collect(toList()); wireError.flagId = error.flagId().map(FlagId::toString).orElse(null); wireError.data = error.flagData().map(FlagData::toWire).orElse(null); wireResult.errors.add(wireError); } wireResult.warnings = new ArrayList<>(); for (Warning warning : warnings) { var wireWarning = new WireWarning(); wireWarning.message = warning.message(); wireWarning.flagId = warning.flagId().toString(); wireWarning.targets = warning.targets().stream().map(FlagsTarget::asString).collect(toList()); wireResult.warnings.add(wireWarning); } return wireResult; } SystemFlagsDeployResult(List<FlagDataChange> flagChanges, List<OperationError> errors, List<Warning> warnings);   SystemFlagsDeployResult(List<OperationError> errors);   }
@Test public void changes_and_errors_are_present_in_wire_format() { FlagsTarget controllerTarget = FlagsTarget.forController(SystemName.cd); FlagId flagOne = new FlagId("flagone"); FlagId flagTwo = new FlagId("flagtwo"); SystemFlagsDeployResult result = new SystemFlagsDeployResult( List.of( FlagDataChange.deleted(flagOne, controllerTarget)), List.of( OperationError.deleteFailed("delete failed", controllerTarget, flagTwo)), List.of()); WireSystemFlagsDeployResult wire = result.toWire(); assertThat(wire.changes).hasSize(1); assertThat(wire.changes.get(0).flagId).isEqualTo(flagOne.toString()); assertThat(wire.errors).hasSize(1); assertThat(wire.errors.get(0).flagId).isEqualTo(flagTwo.toString()); }