From f205722b1944720b364188fd4052569e1e1ef12e Mon Sep 17 00:00:00 2001 From: jflabatBCSS <65955832+jflabatBCSS@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:01:46 +0100 Subject: [PATCH] Add in(Input) in InputValidationIssue for a fluent single input setter (#141) Fixes #140 --------- Co-authored-by: Jimmy Praet --- .../rest/problem/api/InputValidationIssue.java | 8 ++++++++ .../problem/api/InputValidationIssueTest.java | 17 ++++++++++++++++- src/main/asciidoc/release-notes.adoc | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/belgif-rest-problem/src/main/java/io/github/belgif/rest/problem/api/InputValidationIssue.java b/belgif-rest-problem/src/main/java/io/github/belgif/rest/problem/api/InputValidationIssue.java index 27e84f39..9c5c80d2 100644 --- a/belgif-rest-problem/src/main/java/io/github/belgif/rest/problem/api/InputValidationIssue.java +++ b/belgif-rest-problem/src/main/java/io/github/belgif/rest/problem/api/InputValidationIssue.java @@ -263,6 +263,14 @@ public InputValidationIssue in(InEnum in, String name, Object value) { return in(in).name(name).value(value); } + public InputValidationIssue in(Input input) { + if (input != null) { + return in(input.getIn(), input.getName(), input.getValue()); + } else { + return this; + } + } + public InputValidationIssue in(InEnum in) { setIn(in); return this; diff --git a/belgif-rest-problem/src/test/java/io/github/belgif/rest/problem/api/InputValidationIssueTest.java b/belgif-rest-problem/src/test/java/io/github/belgif/rest/problem/api/InputValidationIssueTest.java index 01a6218d..c1c25bd5 100644 --- a/belgif-rest-problem/src/test/java/io/github/belgif/rest/problem/api/InputValidationIssueTest.java +++ b/belgif-rest-problem/src/test/java/io/github/belgif/rest/problem/api/InputValidationIssueTest.java @@ -90,7 +90,7 @@ void in() { issue.setIn(null); assertThat(issue.getIn()).isNull(); - issue.in(null); + issue.in((InEnum) null); assertThat(issue.getIn()).isNull(); issue.setIn(InEnum.QUERY); @@ -98,6 +98,21 @@ void in() { assertThat(new InputValidationIssue().in(InEnum.QUERY).getIn()).isEqualTo(InEnum.QUERY); } + @Test + void inInput() { + InputValidationIssue issue = new InputValidationIssue(); + + issue.in((Input) null); + assertThat(issue.getIn()).isNull(); + assertThat(issue.getName()).isNull(); + assertThat(issue.getValue()).isNull(); + + issue = issue.in(Input.query("name", "value")); + assertThat(issue.getIn()).isEqualTo(InEnum.QUERY); + assertThat(issue.getName()).isEqualTo("name"); + assertThat(issue.getValue()).isEqualTo("value"); + } + @Test void name() { InputValidationIssue issue = new InputValidationIssue(); diff --git a/src/main/asciidoc/release-notes.adoc b/src/main/asciidoc/release-notes.adoc index a13cbe74..756e7fe6 100644 --- a/src/main/asciidoc/release-notes.adoc +++ b/src/main/asciidoc/release-notes.adoc @@ -12,6 +12,12 @@ // tag::recent-versions[] +== Version 0.11 + +*belgif-rest-problem:* + +* Add in(Input) in InputValidationIssue for a fluent single input setter + == Version 0.10 *belgif-rest-problem:*