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

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 8880c00e01 Unit tests
8880c00e01 is described below

commit 8880c00e0103cbc6858eb67279e4f7600ec2d5fd
Author: James Bognar <[email protected]>
AuthorDate: Thu Dec 4 11:13:12 2025 -0800

    Unit tests
---
 .../main/java/org/apache/juneau/config/Config.java |  77 +++++++-------
 .../main/java/org/apache/juneau/config/Entry.java  |  28 ++---
 .../apache/juneau/config/internal/ConfigMap.java   | 114 ++++++++++-----------
 3 files changed, 112 insertions(+), 107 deletions(-)

diff --git 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
index 2130111223..1a6544eded 100644
--- 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
+++ 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Config.java
@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.*;
 import org.apache.juneau.*;
 import org.apache.juneau.collections.*;
 import org.apache.juneau.commons.collections.*;
+import org.apache.juneau.commons.function.*;
 import org.apache.juneau.commons.utils.*;
 import org.apache.juneau.config.event.*;
 import org.apache.juneau.config.internal.*;
@@ -404,9 +405,11 @@ public class Config extends Context implements 
ConfigEventListener {
                }
        }
 
-       private static final boolean DISABLE_AUTO_SYSTEM_PROPS = 
Boolean.getBoolean("juneau.disableAutoSystemProps");
+       // Use set(T)/reset() for testing.
+       static final ResettableSupplier<Boolean> DISABLE_AUTO_SYSTEM_PROPS = 
memoizeResettable(() -> Boolean.getBoolean("juneau.disableAutoSystemProps"));
 
-       private static final AtomicReference<Config> SYSTEM_DEFAULT = new 
AtomicReference<>(findSystemDefault());
+       // Use set(T)/reset() for testing.
+       static final ResettableSupplier<Config> SYSTEM_DEFAULT = 
memoizeResettable(() -> findSystemDefault());
 
        /**
         * Creates a new builder for this object.
@@ -467,10 +470,12 @@ public class Config extends Context implements 
ConfigEventListener {
                        l.add(cmd + ".cfg");
                }
 
-               var files = sortedSet(new File(".").listFiles());
-               for (var f : files)
-                       if (f.getName().endsWith(".cfg"))
-                               l.add(f.getName());
+               var fileArray = new File(".").listFiles();
+               if (fileArray != null) {
+                       for (var f : fileArray)
+                               if (f.getName().endsWith(".cfg"))
+                                       l.add(f.getName());
+               }
 
                l.add("juneau.cfg");
                l.add("default.cfg");
@@ -513,7 +518,7 @@ public class Config extends Context implements 
ConfigEventListener {
                for (var n : getCandidateSystemDefaultConfigNames()) {
                        var config = find(n);
                        if (nn(config)) {
-                               if (! DISABLE_AUTO_SYSTEM_PROPS)
+                               if (! DISABLE_AUTO_SYSTEM_PROPS.get())
                                        config.setSystemProperties();
                                return config;
                        }
@@ -522,6 +527,31 @@ public class Config extends Context implements 
ConfigEventListener {
                return null;
        }
 
+       private static boolean isSimpleType(Type t) {
+               if (! (t instanceof Class))
+                       return false;
+               var c = (Class<?>)t;
+               return (c == String.class || c.isPrimitive() || 
c.isAssignableFrom(Number.class) || c == Boolean.class || c.isEnum());
+       }
+       private static String section(String section) {
+               assertArgNotNull("section", section);
+               if (isEmpty(section))
+                       return "";
+               return section;
+       }
+       private static String skey(String key) {
+               var i = key.indexOf('/');
+               if (i == -1)
+                       return key;
+               return key.substring(i + 1);
+       }
+       private static String sname(String key) {
+               assertArgNotNull("key", key);
+               var i = key.indexOf('/');
+               if (i == -1)
+                       return "";
+               return key.substring(0, i);
+       }
        final String name;
        final ConfigStore store;
        final WriterSerializer serializer;
@@ -529,12 +559,16 @@ public class Config extends Context implements 
ConfigEventListener {
        final Map<Character,Mod> mods;
        final VarResolver varResolver;
        final int binaryLineLength;
+
        final BinaryFormat binaryFormat;
        final boolean multiLineValuesOnSeparateLines, readOnly;
+
        final BeanSession beanSession;
+
        final VarResolverSession varSession;
 
        private final ConfigMap configMap;
+
        private final List<ConfigEventListener> listeners = synced(new 
LinkedList<>());
 
        /**
@@ -1118,13 +1152,6 @@ public class Config extends Context implements 
ConfigEventListener {
                return removeMods(ce.getModifiers(), ce.getValue());
        }
 
-       private static boolean isSimpleType(Type t) {
-               if (! (t instanceof Class))
-                       return false;
-               var c = (Class<?>)t;
-               return (c == String.class || c.isPrimitive() || 
c.isAssignableFrom(Number.class) || c == Boolean.class || c.isEnum());
-       }
-
        private String nlIfMl(CharSequence cs) {
                var s = cs.toString();
                if (s.indexOf('\n') != -1 && multiLineValuesOnSeparateLines)
@@ -1132,13 +1159,6 @@ public class Config extends Context implements 
ConfigEventListener {
                return s;
        }
 
-       private static String section(String section) {
-               assertArgNotNull("section", section);
-               if (isEmpty(section))
-                       return "";
-               return section;
-       }
-
        private String serialize(Object value, Serializer serializer) throws 
SerializeException {
                if (value == null)
                        return "";
@@ -1178,21 +1198,6 @@ public class Config extends Context implements 
ConfigEventListener {
                return r;
        }
 
-       private static String skey(String key) {
-               var i = key.indexOf('/');
-               if (i == -1)
-                       return key;
-               return key.substring(i + 1);
-       }
-
-       private static String sname(String key) {
-               assertArgNotNull("key", key);
-               var i = key.indexOf('/');
-               if (i == -1)
-                       return "";
-               return key.substring(0, i);
-       }
-
        String applyMods(String mods, String x) {
                if (nn(mods) && nn(x))
                        for (var i = 0; i < mods.length(); i++)
diff --git 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Entry.java 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Entry.java
index dbf5ae682e..416840d6d4 100644
--- 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Entry.java
+++ 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/Entry.java
@@ -37,8 +37,22 @@ import org.apache.juneau.parser.*;
  */
 public class Entry {
 
+       private static boolean isArray(Type t) {
+               if (! (t instanceof Class))
+                       return false;
+               var c = (Class<?>)t;
+               return (c.isArray());
+       }
+       private static boolean isSimpleType(Type t) {
+               if (! (t instanceof Class))
+                       return false;
+               var c = (Class<?>)t;
+               return (c == String.class || c.isPrimitive() || 
c.isAssignableFrom(Number.class) || c == Boolean.class || c.isEnum());
+       }
        private final ConfigMapEntry configEntry;
+
        private final Config config;
+
        private final String value;
 
        /**
@@ -543,21 +557,7 @@ public class Entry {
                return isPresent() ? config.varSession.resolve(value) : null;
        }
 
-       private static boolean isArray(Type t) {
-               if (! (t instanceof Class))
-                       return false;
-               var c = (Class<?>)t;
-               return (c.isArray());
-       }
-
        private boolean isEmpty() { return Utils.isEmpty(value); }  // NOAI
 
        private boolean isNull() { return value == null; }
-
-       private static boolean isSimpleType(Type t) {
-               if (! (t instanceof Class))
-                       return false;
-               var c = (Class<?>)t;
-               return (c == String.class || c.isPrimitive() || 
c.isAssignableFrom(Number.class) || c == Boolean.class || c.isEnum());
-       }
 }
\ No newline at end of file
diff --git 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/internal/ConfigMap.java
 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/internal/ConfigMap.java
index 07bb259027..f7a5ef2fff 100644
--- 
a/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/internal/ConfigMap.java
+++ 
b/juneau-core/juneau-config/src/main/java/org/apache/juneau/config/internal/ConfigMap.java
@@ -184,6 +184,63 @@ public class ConfigMap implements ConfigStoreListener {
                }
        }
 
+       private static void checkKeyName(String s) {
+               if (! isValidKeyName(s))
+                       throw illegalArg("Invalid key name: ''{0}''", s);
+       }
+
+       private static void checkSectionName(String s) {
+               if (! ("".equals(s) || isValidNewSectionName(s)))
+                       throw illegalArg("Invalid section name: ''{0}''", s);
+       }
+
+       private static boolean isValidConfigName(String s) {
+               if (s == null)
+                       return false;
+               s = s.trim();
+               if (s.isEmpty())
+                       return false;
+               for (var i = 0; i < s.length(); i++) {
+                       var c = s.charAt(i);
+                       if (i == 0) {
+                               if (! Character.isJavaIdentifierStart(c))
+                                       return false;
+                       } else {
+                               if (! Character.isJavaIdentifierPart(c))
+                                       return false;
+                       }
+               }
+               return true;
+       }
+
+       private static boolean isValidKeyName(String s) {
+               if (s == null)
+                       return false;
+               s = s.trim();
+               if (s.isEmpty())
+                       return false;
+               for (var i = 0; i < s.length(); i++) {
+                       var c = s.charAt(i);
+                       if (c == '/' || c == '\\' || c == '[' || c == ']' || c 
== '=' || c == '#')
+                               return false;
+               }
+               return true;
+       }
+
+       private static boolean isValidNewSectionName(String s) {
+               if (s == null)
+                       return false;
+               s = s.trim();
+               if (s.isEmpty())
+                       return false;
+               for (var i = 0; i < s.length(); i++) {
+                       var c = s.charAt(i);
+                       if (c == '/' || c == '\\' || c == '[' || c == ']')
+                               return false;
+               }
+               return true;
+       }
+
        private final ConfigStore store;         // The store that created this 
object.
 
        private volatile String contents;        // The original contents of 
this object.
@@ -669,16 +726,6 @@ public class ConfigMap implements ConfigStoreListener {
                }
        }
 
-       private static void checkKeyName(String s) {
-               if (! isValidKeyName(s))
-                       throw illegalArg("Invalid key name: ''{0}''", s);
-       }
-
-       private static void checkSectionName(String s) {
-               if (! ("".equals(s) || isValidNewSectionName(s)))
-                       throw illegalArg("Invalid section name: ''{0}''", s);
-       }
-
        private ConfigEvents findDiffs(String updatedContents) throws 
IOException {
                var changes2 = new ConfigEvents();
                var newMap = new ConfigMap(store, name, updatedContents);
@@ -742,53 +789,6 @@ public class ConfigMap implements ConfigStoreListener {
                return changes2;
        }
 
-       private static boolean isValidConfigName(String s) {
-               if (s == null)
-                       return false;
-               s = s.trim();
-               if (s.isEmpty())
-                       return false;
-               for (var i = 0; i < s.length(); i++) {
-                       var c = s.charAt(i);
-                       if (i == 0) {
-                               if (! Character.isJavaIdentifierStart(c))
-                                       return false;
-                       } else {
-                               if (! Character.isJavaIdentifierPart(c))
-                                       return false;
-                       }
-               }
-               return true;
-       }
-
-       private static boolean isValidKeyName(String s) {
-               if (s == null)
-                       return false;
-               s = s.trim();
-               if (s.isEmpty())
-                       return false;
-               for (var i = 0; i < s.length(); i++) {
-                       var c = s.charAt(i);
-                       if (c == '/' || c == '\\' || c == '[' || c == ']' || c 
== '=' || c == '#')
-                               return false;
-               }
-               return true;
-       }
-
-       private static boolean isValidNewSectionName(String s) {
-               if (s == null)
-                       return false;
-               s = s.trim();
-               if (s.isEmpty())
-                       return false;
-               for (var i = 0; i < s.length(); i++) {
-                       var c = s.charAt(i);
-                       if (c == '/' || c == '\\' || c == '[' || c == ']')
-                               return false;
-               }
-               return true;
-       }
-
        private ConfigMap load(String contents) throws IOException {
                if (contents == null)
                        contents = "";

Reply via email to