You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/28 15:43:24 UTC

[isis] branch ISIS-2773 created (now af68b3e)

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a change to branch ISIS-2773
in repository https://gitbox.apache.org/repos/asf/isis.git.


      at af68b3e  ISIS-2773: adds FixtureScript#optionalParam()

This branch includes the following new commits:

     new af68b3e  ISIS-2773: adds FixtureScript#optionalParam()

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[isis] 01/01: ISIS-2773: adds FixtureScript#optionalParam()

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2773
in repository https://gitbox.apache.org/repos/asf/isis.git

commit af68b3e6d013fac51bde18102ed826ec0f12195d
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Jun 28 16:41:46 2021 +0100

    ISIS-2773: adds FixtureScript#optionalParam()
---
 .../fixtures/applib/fixturescripts/FixtureScript.java        | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/fixturescripts/FixtureScript.java b/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/fixturescripts/FixtureScript.java
index 10ebb97..de65f21 100644
--- a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/fixturescripts/FixtureScript.java
+++ b/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/fixturescripts/FixtureScript.java
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
@@ -695,13 +696,14 @@ public abstract class FixtureScript {
         return defaultValue;
     }
 
-    protected <T> T checkParam(final String parameterName, final ExecutionContext ec, final Class<T> cls) {
-
+    protected <T> Optional<T> optionalParam(final String parameterName, final ExecutionContext ec, final Class<T> cls) {
         final T value = readParam(parameterName, ec, cls);
-        if(value != null) { return (T) value; }
+        return Optional.ofNullable(value);
+    }
 
-        // else throw exception
-        throw new IllegalArgumentException(String.format("No value for '%s'", parameterName));
+    protected <T> T checkParam(final String parameterName, final ExecutionContext ec, final Class<T> cls) {
+        return optionalParam(parameterName, ec, cls)
+                .orElseThrow(() -> new IllegalArgumentException(String.format("No value for '%s'", parameterName)));
     }
 
     private <T> T readParam(final String parameterName, final ExecutionContext ec, final Class<T> cls) {