[java-opensaml] branch master updated: IDP-1593 KeyWords should return an empty list not a null one

Rod Widdowson rdw at steadingsoftware.com
Sun Apr 19 10:38:33 EDT 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=fffab27f0d5cafbe9e97a1d862d5b1bb3f87862b

The following commit(s) were added to refs/heads/master by this push:
       new  fffab27   IDP-1593 KeyWords should return an empty list not a null one
fffab27 is described below

commit fffab27f0d5cafbe9e97a1d862d5b1bb3f87862b
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Apr 19 15:36:35 2020 +0100

    IDP-1593 KeyWords should return an empty list not a null one
    
    https://issues.shibboleth.net/jira/browse/IDP-1593
    
    Also fix a warning about hashcode/equality not both being implemented
    and add test
---
 .../saml/ext/saml2mdui/impl/KeywordsImpl.java      | 43 +++++++++++++++++++++-
 .../saml/ext/saml2mdui/impl/KeywordsTest.java      | 17 +++++++--
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsImpl.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsImpl.java
index 655cd59..c93705f 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsImpl.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsImpl.java
@@ -17,8 +17,12 @@
 
 package org.opensaml.saml.ext.saml2mdui.impl;
 
+import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.core.xml.AbstractXMLObject;
 import org.opensaml.core.xml.LangBearing;
 import org.opensaml.core.xml.XMLObject;
@@ -34,7 +38,7 @@ public class KeywordsImpl extends AbstractXMLObject implements Keywords {
     /** The language. */
     private String lang;
     /** The data. */
-    private List<String> data;
+    @Nonnull private List<String> data = Collections.emptyList();
     /**
      * Constructor.
      *
@@ -78,11 +82,46 @@ public class KeywordsImpl extends AbstractXMLObject implements Keywords {
      * {@inheritDoc}
      */
     public int hashCode() {
-        int hash = lang.hashCode();
+        int hash = lang == null ? 12 :lang.hashCode();
         for (final String s: data) {
             hash = hash * 31 + s.hashCode();
         }
         return hash; 
     }
 
+    /** {@inheritDoc} */
+    public boolean equals(final Object obj) {
+        if (!(obj instanceof Keywords)) {
+            return false;
+        }
+        final Keywords other = (Keywords) obj;
+
+        if (lang == null) {
+            if (other.getXMLLang() != null) {
+                return false;
+            }
+        } else if (!lang.equals(other.getXMLLang())) {
+            return false;
+        }
+
+        List<String> otherList = other.getKeywords();
+        if (otherList == null) {
+            otherList = Collections.emptyList();
+        }
+
+        if (otherList.size() != data.size()) {
+            return false;
+        }
+
+        final Iterator<String> me = data.iterator();
+        final Iterator<String> him = otherList.iterator();
+
+        while (me.hasNext()) {
+            if (!me.next().equals(him.next())) {
+                return false;
+            }
+        }
+        return true;
+    }
+
 }
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsTest.java
index d79dc65..5e584c1 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/KeywordsTest.java
@@ -20,13 +20,15 @@
  */
 package org.opensaml.saml.ext.saml2mdui.impl;
 
-import org.testng.annotations.Test;
-import org.testng.Assert;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import org.opensaml.core.xml.XMLObjectProviderBaseTestCase;
 import org.opensaml.saml.ext.saml2mdui.Keywords;
+import org.testng.annotations.Test;
 
 /**
  * Test case for creating, marshalling, and unmarshalling
@@ -57,8 +59,15 @@ public class KeywordsTest extends XMLObjectProviderBaseTestCase {
     public void testSingleElementUnmarshall() {
         Keywords name = (Keywords) unmarshallElement(singleElementFile);
         
-        Assert.assertEquals(name.getKeywords(), expectedWords, "Keyworks were not expected value");
-        Assert.assertEquals(name.getXMLLang(), expectedLang, "Language was not expected value");
+        assertEquals(name.getKeywords(), expectedWords, "Keyworks were not expected value");
+        assertEquals(name.getXMLLang(), expectedLang, "Language was not expected value");
+
+        Keywords keywords = (Keywords) buildXMLObject(Keywords.DEFAULT_ELEMENT_NAME);
+        assertNotEquals(keywords, name);
+        keywords.setXMLLang(expectedLang);
+        assertNotEquals(keywords, name);
+        keywords.setKeywords(expectedWords);
+        assertEquals(keywords, name);
     }
 
     /** {@inheritDoc} */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list