changeset 7370:bc10f48ef71f

RT-37732:[packager] Default argument lambdas should be well behaved Summary: Deal with the case of a null identifier. Add unit tests as well.
author shemnon
date Thu, 26 Jun 2014 13:30:09 -0600
parents 796678138fdf
children 8d41ccb6bcdb
files modules/fxpackager/src/main/java/com/oracle/tools/packager/StandardBundlerParam.java modules/fxpackager/src/test/java/com/oracle/tools/packager/BundlersTest.java
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxpackager/src/main/java/com/oracle/tools/packager/StandardBundlerParam.java	Thu Jun 26 15:04:59 2014 -0400
+++ b/modules/fxpackager/src/main/java/com/oracle/tools/packager/StandardBundlerParam.java	Thu Jun 26 13:30:09 2014 -0600
@@ -436,7 +436,7 @@
                     I18N.getString("param.preferences-id.description"),
                     "preferencesID",
                     String.class,
-                    p -> IDENTIFIER.fetchFrom(p).replace('.', '/'),
+                    p -> Optional.ofNullable(IDENTIFIER.fetchFrom(p)).orElse("").replace('.', '/'),
                     (s, p) -> s
             );
 
--- a/modules/fxpackager/src/test/java/com/oracle/tools/packager/BundlersTest.java	Thu Jun 26 15:04:59 2014 -0400
+++ b/modules/fxpackager/src/test/java/com/oracle/tools/packager/BundlersTest.java	Thu Jun 26 13:30:09 2014 -0600
@@ -122,11 +122,18 @@
     }
     
     boolean assertMetadata(Bundler bundler, BundlerParamInfo<?> bpi, String checkDescription, Function<BundlerParamInfo, Boolean> check) {
-        if (!check.apply(bpi)) {
+        try {
+            if (!check.apply(bpi)) {
+                System.err.println("Bundler '" + bundler.getID() + "' parameter '" + bpi.getID() + "' failed metadata check: " + checkDescription);
+                return false;
+            } else {
+                return true;
+            }
+        } catch (RuntimeException re) {
             System.err.println("Bundler '" + bundler.getID() + "' parameter '" + bpi.getID() + "' failed metadata check: " + checkDescription);
+            System.err.println("Exception was thrown");
+            re.printStackTrace(System.err);
             return false;
-        } else {
-            return true;
         }
     }
     
@@ -143,6 +150,8 @@
                 metadataValid &= assertMetadata(bundler, bpi, "ID is not null", param -> param.getID() != null);
                 metadataValid &= assertMetadata(bundler, bpi, "Description is not null", param -> param.getDescription() != null);
                 metadataValid &= assertMetadata(bundler, bpi, "ValueType is not null", param -> param.getValueType() != null);
+                // the second option is a nonsense comparison to execute the lambda if not null, to fish for exceptions
+                metadataValid &= assertMetadata(bundler, bpi, "DefaultValueFunction if not null behaves with empty map", param -> param.getDefaultValueFunction() == null || param.getDefaultValueFunction().apply(new HashMap()) != this );
             }
         }