[java-identity-provider COMMIT] in /trunk/idp-attribute-api/src: main/java/net/shibboleth/idp/attribute/Attribute.jav...

noreply at shibboleth.net noreply at shibboleth.net
Sun Mar 18 12:36:43 GMT 2012


Author: rdw
Date: Sun Mar 18 12:36:42 2012
New Revision: 4124

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4124&view=rev
Log:
Enhances testing from code coverage.  Fixes to Attributes (encoders are unmodifibale once set, clone throws  CloseUnsupported)

Added:
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeContextTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/LocalizedStringAttributeValueTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/StringAttributeValueTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/logic/
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/logic/AttributeValuePredicateTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/logic/LookupAttributeFromAttributeContextFunctionTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/logic/ScopedStringAttributeValuePredicateTest.java   (with props)
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/logic/StringAttributeValuePredicateTest.java   (with props)
Modified:
    trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/Attribute.java
    trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/UnsupportedAttributeTypeException.java
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/AttributeTest.java
    trunk/idp-attribute-api/src/test/java/net/shibboleth/idp/attribute/ScopedStringAttributeValueTest.java

Modified: trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/Attribute.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/Attribute.java?rev=4124&r1=4123&r2=4124&view=diff
==============================================================================
--- trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/Attribute.java (original)
+++ trunk/idp-attribute-api/src/main/java/net/shibboleth/idp/attribute/Attribute.java Sun Mar 18 12:36:42 2012
@@ -42,6 +42,7 @@
 import com.google.common.base.Predicates;
 import com.google.common.collect.Constraints;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * Each attribute represents one piece of information about a user and has associated encoders used to turn that
@@ -80,7 +81,7 @@
         displayDescriptions = Collections.emptyMap();
 
         values = Constraints.constrainedSet(new HashSet<AttributeValue>(), Constraints.notNull());
-        encoders = Constraints.constrainedSet(new HashSet<AttributeEncoder<?>>(), Constraints.notNull());
+        encoders = Collections.emptySet();
     }
 
     /**
@@ -102,21 +103,37 @@
     }
 
     /**
+     * Process input to {@link #setDisplayNames(Map)} and {{@link #setDisplayDescriptions(Map)} to strip out null input,
+     * null keys, and null values.
+     * 
+     * @param inputMap the input map.
+     * @return the unmodifable, non null-containing output.
+     */
+    @Nonnull @NonnullElements @Unmodifiable private Map<Locale, String> checkedNamesFrom(
+            @Nullable @NullableElements final Map<Locale, String> inputMap) {
+        HashMap<Locale, String> checkedMap = new HashMap<Locale, String>();
+        String trimmedName;
+
+        if (inputMap != null) {
+            for (Entry<Locale, String> entry : inputMap.entrySet()) {
+                if (entry.getKey() != null) {
+                    trimmedName = StringSupport.trimOrNull(entry.getValue());
+                    if (trimmedName != null) {
+                        checkedMap.put(entry.getKey(), trimmedName);
+                    }
+                }
+            }
+        }
+        return ImmutableMap.copyOf(checkedMap);
+    }
+
+    /**
      * Replaces the existing display names for this attribute with the given ones.
      * 
      * @param newNames the new names for this attribute
      */
     public void setDisplayNames(@Nullable @NullableElements final Map<Locale, String> newNames) {
-        HashMap<Locale, String> checkedNames = new HashMap<Locale, String>();
-        String trimmedName;
-        for (Entry<Locale, String> entry : newNames.entrySet()) {
-            trimmedName = StringSupport.trimOrNull(entry.getValue());
-            if (trimmedName != null) {
-                checkedNames.put(entry.getKey(), trimmedName);
-            }
-        }
-
-        displayNames = ImmutableMap.copyOf(checkedNames);
+        displayNames = checkedNamesFrom(newNames);
     }
 
     /**
@@ -134,16 +151,7 @@
      * @param newDescriptions the new descriptions for this attribute
      */
     public void setDisplayDescriptions(@Nullable @NullableElements final Map<Locale, String> newDescriptions) {
-        HashMap<Locale, String> checkedDescriptions = new HashMap<Locale, String>();
-        String trimmedDescription;

[... 630 lines stripped ...]


More information about the commits mailing list