[java-shib-shared] branch main updated: Tighten AttributeSupport API.
Scott Cantor
cantor.2 at osu.edu
Tue Mar 7 18:25:00 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=cb270eff3a758601326ec3833be027786db1c7e2
The following commit(s) were added to refs/heads/main by this push:
new cb270eff Tighten AttributeSupport API.
cb270eff is described below
commit cb270eff3a758601326ec3833be027786db1c7e2
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 7 13:24:57 2023 -0500
Tighten AttributeSupport API.
---
.../shibboleth/shared/xml/AttributeSupport.java | 86 +++++--------
.../net/shibboleth/shared/xml/XMLConstants.java | 38 +++---
.../shared/xml/AttributeSupportTest.java | 140 ++++++++++++---------
3 files changed, 130 insertions(+), 134 deletions(-)
diff --git a/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java b/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
index bac6fcc3..a4de1bb3 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/xml/AttributeSupport.java
@@ -19,7 +19,6 @@ package net.shibboleth.shared.xml;
import java.time.Duration;
import java.time.Instant;
-import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
@@ -27,6 +26,8 @@ import javax.annotation.Nullable;
import javax.xml.namespace.QName;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.annotation.constraint.NotLive;
+import net.shibboleth.shared.annotation.constraint.Unmodifiable;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.StringSupport;
@@ -240,11 +241,7 @@ public final class AttributeSupport {
* @return the attribute or null if the given element or attribute was null or the given attribute did not contain
* an attribute with the given name
*/
- @Nullable public static Attr getAttribute(@Nullable final Element element, @Nullable final QName attributeName) {
- if (element == null || attributeName == null) {
- return null;
- }
-
+ @Nullable public static Attr getAttribute(@Nonnull final Element element, @Nonnull final QName attributeName) {
return element.getAttributeNodeNS(StringSupport.trimOrNull(attributeName.getNamespaceURI()),
attributeName.getLocalPart());
}
@@ -257,12 +254,8 @@ public final class AttributeSupport {
*
* @return the value of the attribute or null if the element does not have such an attribute
*/
- @Nullable public static String getAttributeValue(@Nullable final Element element,
- @Nullable final QName attributeName) {
- if (element == null || attributeName == null) {
- return null;
- }
-
+ @Nullable public static String getAttributeValue(@Nonnull final Element element,
+ @Nonnull final QName attributeName) {
return getAttributeValue(element, StringSupport.trimOrNull(attributeName.getNamespaceURI()),
attributeName.getLocalPart());
}
@@ -276,12 +269,8 @@ public final class AttributeSupport {
*
* @return the value of the attribute or null if the element does not have such an attribute
*/
- @Nullable public static String getAttributeValue(@Nullable final Element element, @Nullable final String namespace,
- @Nullable final String attributeLocalName) {
- if (element == null || attributeLocalName == null) {
- return null;
- }
-
+ @Nullable public static String getAttributeValue(@Nonnull final Element element, @Nullable final String namespace,
+ @Nonnull @NotEmpty final String attributeLocalName) {
final Attr attr = element.getAttributeNodeNS(namespace, attributeLocalName);
if (attr == null) {
return null;
@@ -301,7 +290,7 @@ public final class AttributeSupport {
*
* @since 9.0.0
*/
- @Nonnull @NotEmpty public static String ensureAttributeValue(@Nullable final Element element,
+ @Nonnull @NotEmpty public static String ensureAttributeValue(@Nonnull final Element element,
@Nullable final String namespace, @Nonnull @NotEmpty final String attributeLocalName) {
return Constraint.isNotNull(StringSupport.trimOrNull(
getAttributeValue(element, namespace, attributeLocalName)),
@@ -319,7 +308,7 @@ public final class AttributeSupport {
*
* @since 9.0.0
*/
- @Nonnull @NotEmpty public static String ensureAttributeValue(@Nullable final Element element,
+ @Nonnull @NotEmpty public static String ensureAttributeValue(@Nonnull final Element element,
@Nonnull final QName attributeName) {
return Constraint.isNotNull(StringSupport.trimOrNull(getAttributeValue(element, attributeName)),
attributeName.getLocalPart() + " cannot be null or empty");
@@ -334,10 +323,7 @@ public final class AttributeSupport {
* @return boolean value of the attribute or null
* late enough to allow property replacement.
*/
- @Nullable public static Boolean getAttributeValueAsBoolean(@Nullable final Attr attribute) {
- if (attribute == null) {
- return null;
- }
+ @Nullable public static Boolean getAttributeValueAsBoolean(@Nonnull final Attr attribute) {
final String valueStr = StringSupport.trimOrNull(attribute.getValue());
if ("0".equals(valueStr) || "false".equals(valueStr)) {
@@ -356,11 +342,12 @@ public final class AttributeSupport {
*
* @return list of values, never null
*/
- @Nonnull public static List<String> getAttributeValueAsList(@Nullable final Attr attribute) {
- if (attribute == null) {
- return CollectionSupport.emptyList();
+ @Nonnull @Unmodifiable @NotLive public static List<String> getAttributeValueAsList(@Nonnull final Attr attribute) {
+ final String value = StringSupport.trimOrNull(attribute.getTextContent());
+ if (value != null) {
+ return StringSupport.stringToList(value, XMLConstants.LIST_DELIMITERS);
}
- return StringSupport.stringToList(attribute.getValue(), XMLConstants.LIST_DELIMITERS);
+ return CollectionSupport.emptyList();
}
/**
@@ -370,10 +357,7 @@ public final class AttributeSupport {
*
* @return a QName from an attributes value, or null if the given attribute is null
*/
- @Nullable public static QName getAttributeValueAsQName(@Nullable final Attr attribute) {
- if (attribute == null) {
- return null;
- }
+ @Nullable public static QName getAttributeValueAsQName(@Nonnull final Attr attribute) {
final String attributeValue = StringSupport.trimOrNull(attribute.getTextContent());
if (attributeValue == null) {
@@ -395,12 +379,10 @@ public final class AttributeSupport {
*
* @return date/time as an {@link Instant}, or null if the attribute was null
*/
- @Nullable public static Instant getDateTimeAttribute(@Nullable final Attr attribute) {
- if (attribute == null || StringSupport.trimOrNull(attribute.getValue()) == null) {
- return null;
- }
-
- return DOMTypeSupport.stringToInstant(attribute.getValue());
+ @Nullable public static Instant getDateTimeAttribute(@Nonnull final Attr attribute) {
+ final String value = StringSupport.trimOrNull(attribute.getValue());
+
+ return value != null ? DOMTypeSupport.stringToInstant(value) : null;
}
/**
@@ -410,12 +392,10 @@ public final class AttributeSupport {
*
* @return duration, or null if the attribute was null
*/
- @Nullable public static Duration getDurationAttributeValue(@Nullable final Attr attribute) {
- if (attribute == null || StringSupport.trimOrNull(attribute.getValue()) == null) {
- return null;
- }
+ @Nullable public static Duration getDurationAttributeValue(@Nonnull final Attr attribute) {
+ final String value = StringSupport.trimOrNull(attribute.getValue());
- return DOMTypeSupport.stringToDuration(attribute.getValue());
+ return value != null ? DOMTypeSupport.stringToDuration(value) : null;
}
/**
@@ -425,8 +405,8 @@ public final class AttributeSupport {
*
* @return the ID attribute or null if there isn't one
*/
- @Nullable public static Attr getIdAttribute(@Nullable final Element element) {
- if (element == null || !element.hasAttributes()) {
+ @Nullable public static Attr getIdAttribute(@Nonnull final Element element) {
+ if (!element.hasAttributes()) {
return null;
}
@@ -449,7 +429,7 @@ public final class AttributeSupport {
*
* @return the value of the xml:base attribute, or null if not present
*/
- @Nullable public static String getXMLBase(@Nullable final Element element) {
+ @Nullable public static String getXMLBase(@Nonnull final Element element) {
return getAttributeValue(element, XMLConstants.XML_BASE_ATTRIB_NAME);
}
@@ -460,7 +440,7 @@ public final class AttributeSupport {
*
* @return the value of the xml:id attribute, or null if not present
*/
- @Nullable public static String getXMLId(@Nullable final Element element) {
+ @Nullable public static String getXMLId(@Nonnull final Element element) {
return getAttributeValue(element, XMLConstants.XML_ID_ATTRIB_NAME);
}
@@ -471,7 +451,7 @@ public final class AttributeSupport {
*
* @return the value of the xml:lang attribute, or null if not present
*/
- @Nullable public static String getXMLLang(@Nullable final Element element) {
+ @Nullable public static String getXMLLang(@Nonnull final Element element) {
return getAttributeValue(element, XMLConstants.XML_LANG_ATTRIB_NAME);
}
@@ -506,11 +486,7 @@ public final class AttributeSupport {
*
* @return true if the element has an attribute with the given name, false otherwise
*/
- public static boolean hasAttribute(@Nullable final Element element, @Nullable final QName name) {
- if (element == null || name == null) {
- return false;
- }
-
+ public static boolean hasAttribute(@Nonnull final Element element, @Nonnull final QName name) {
return element.hasAttributeNS(StringSupport.trimOrNull(name.getNamespaceURI()), name.getLocalPart());
}
@@ -523,8 +499,8 @@ public final class AttributeSupport {
* @return true if the element contained the attribute and it was removed, false if the element did not contain such
* an attribute
*/
- public static boolean removeAttribute(@Nullable final Element element, @Nullable final QName attributeName) {
- if (hasAttribute(element, attributeName) && null != element && null != attributeName) {
+ public static boolean removeAttribute(@Nonnull final Element element, @Nonnull final QName attributeName) {
+ if (hasAttribute(element, attributeName)) {
element.removeAttributeNS(StringSupport.trimOrNull(attributeName.getNamespaceURI()),
attributeName.getLocalPart());
return true;
diff --git a/shib-support/src/main/java/net/shibboleth/shared/xml/XMLConstants.java b/shib-support/src/main/java/net/shibboleth/shared/xml/XMLConstants.java
index 9192d51b..243438e7 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/xml/XMLConstants.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/xml/XMLConstants.java
@@ -17,68 +17,72 @@
package net.shibboleth.shared.xml;
+import javax.annotation.Nonnull;
import javax.xml.namespace.QName;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+
/** XML related constants. */
public final class XMLConstants {
// XML
/** XML core namespace. */
- public static final String XML_NS = "http://www.w3.org/XML/1998/namespace";
+ @Nonnull @NotEmpty public static final String XML_NS = "http://www.w3.org/XML/1998/namespace";
/** XML core prefix for xml attributes. */
- public static final String XML_PREFIX = "xml";
+ @Nonnull @NotEmpty public static final String XML_PREFIX = "xml";
/** QName for the xml:base attribute. */
- public static final QName XML_BASE_ATTRIB_NAME = new QName(XML_NS, "base", XML_PREFIX);
+ @Nonnull public static final QName XML_BASE_ATTRIB_NAME = new QName(XML_NS, "base", XML_PREFIX);
/** QName for the xml:id attribute. */
- public static final QName XML_ID_ATTRIB_NAME = new QName(XML_NS, "id", XML_PREFIX);
+ @Nonnull public static final QName XML_ID_ATTRIB_NAME = new QName(XML_NS, "id", XML_PREFIX);
/** QName for the xml:lang attribute. */
- public static final QName XML_LANG_ATTRIB_NAME = new QName(XML_NS, "lang", XML_PREFIX);
+ @Nonnull public static final QName XML_LANG_ATTRIB_NAME = new QName(XML_NS, "lang", XML_PREFIX);
/** QName for the xml:space attribute. */
- public static final QName XML_SPACE_ATTRIB_NAME = new QName(XML_NS, "space", XML_PREFIX);
+ @Nonnull public static final QName XML_SPACE_ATTRIB_NAME = new QName(XML_NS, "space", XML_PREFIX);
/**
* A string which contains the valid delimiters for the XML Schema 'list' type. These are: space, newline, carriage
* return, and tab.
*/
- public static final String LIST_DELIMITERS = " \n\r\t";
+ @Nonnull @NotEmpty public static final String LIST_DELIMITERS = " \n\r\t";
// XML Namespace
/** XML namespace for xmlns attributes. */
- public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
+ @Nonnull @NotEmpty public static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
/** XML namespace prefix for xmlns attributes. */
- public static final String XMLNS_PREFIX = "xmlns";
+ @Nonnull @NotEmpty public static final String XMLNS_PREFIX = "xmlns";
// XML Schema
/** XML Schema namespace. */
- public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
+ @Nonnull @NotEmpty public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
/** XML Schema QName prefix. */
- public static final String XSD_PREFIX = "xsd";
+ @Nonnull @NotEmpty public static final String XSD_PREFIX = "xsd";
/** XML Schema Instance namespace. */
- public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
+ @Nonnull @NotEmpty public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
/** XML Schema Instance QName prefix. */
- public static final String XSI_PREFIX = "xsi";
+ @Nonnull @NotEmpty public static final String XSI_PREFIX = "xsi";
/** XML Schema instance <code>xsi:type</code> attribute QName. */
- public static final QName XSI_TYPE_ATTRIB_NAME = new QName(XSI_NS, "type", XSI_PREFIX);
+ @Nonnull public static final QName XSI_TYPE_ATTRIB_NAME = new QName(XSI_NS, "type", XSI_PREFIX);
/** XML Schema instance <code>xsi:schemaLocation</code> attribute QName. */
- public static final QName XSI_SCHEMA_LOCATION_ATTRIB_NAME = new QName(XSI_NS, "schemaLocation", XSI_PREFIX);
+ @Nonnull public static final QName XSI_SCHEMA_LOCATION_ATTRIB_NAME =
+ new QName(XSI_NS, "schemaLocation", XSI_PREFIX);
/** XML Schema instance <code>xsi:noNamespaceSchemaLocation</code> attribute QName. */
- public static final QName XSI_NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB_NAME = new QName(XSI_NS,
+ @Nonnull public static final QName XSI_NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB_NAME = new QName(XSI_NS,
"noNamespaceSchemaLocation", XSI_PREFIX);
/** XML Schema instance <code>xsi:nil</code> attribute QName. */
- public static final QName XSI_NIL_ATTRIB_NAME = new QName(XSI_NS, "nil", XSI_PREFIX);
+ @Nonnull public static final QName XSI_NIL_ATTRIB_NAME = new QName(XSI_NS, "nil", XSI_PREFIX);
/** Constructor. */
private XMLConstants() {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/AttributeSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/AttributeSupportTest.java
index 9b598e7c..0294a1c5 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/AttributeSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/AttributeSupportTest.java
@@ -33,6 +33,7 @@ import javax.xml.parsers.DocumentBuilder;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.logic.ConstraintViolationException;
import net.shibboleth.shared.xml.impl.BasicParserPool;
@@ -287,7 +288,6 @@ public class AttributeSupportTest {
}
@Test public void testGetID() {
- assertNull(AttributeSupport.getIdAttribute(null), "ID of null is null");
assertNull(AttributeSupport.getIdAttribute(createdElement), "ID of non id'd element is null");
final Attr attr = AttributeSupport.getIdAttribute((Element) createdElement.getFirstChild());
@@ -299,10 +299,6 @@ public class AttributeSupportTest {
}
@Test public void testHasAttribute() {
- // either parameter null means a false result, not an NPE
- assertFalse(AttributeSupport.hasAttribute(null, idAttrQName));
- assertFalse(AttributeSupport.hasAttribute(createdElement, null));
-
assertFalse(AttributeSupport.hasAttribute(createdElement, idAttrQName), "Attribute lookup by QName");
assertTrue(AttributeSupport.hasAttribute(goodBaseIdSpaceLang, XMLConstants.XML_BASE_ATTRIB_NAME),
@@ -352,22 +348,14 @@ public class AttributeSupportTest {
"Should have found correct attribute by value for xml_id attribute");
// getAttributeValue(Element, QName)
- assertNull(AttributeSupport.getAttributeValue(goodBaseIdSpaceLang, null),
- "no xml:id (lookup value with null QName)");
- assertNull(AttributeSupport.getAttributeValue(null, XMLConstants.XML_ID_ATTRIB_NAME),
- "no xml:id (lookup value with null element)");
assertNull(AttributeSupport.getAttributeValue(noBaseIdSpaceLang, XMLConstants.XML_ID_ATTRIB_NAME),
"no xml:id (lookup value by QName)");
assertEquals(AttributeSupport.getAttributeValue(goodBaseIdSpaceLang, XMLConstants.XML_ID_ATTRIB_NAME),
"identifierGoodBaseIdSpaceLang", "Should have found correct value for xml:id attribute by QName");
// getAttributeValue(Element, String, String)
- assertNull(AttributeSupport.getAttributeValue(badSpace, XMLConstants.XML_NS, null),
- "no value lookup with null name)");
assertNull(AttributeSupport.getAttributeValue(badSpace, XMLConstants.XML_NS, ""),
"no value lookup with empty name)");
- assertNull(AttributeSupport.getAttributeValue(null, XMLConstants.XML_NS, "space"),
- "no value lookup with null element)");
assertNull(AttributeSupport.getAttributeValue(noBaseIdSpaceLang, XMLConstants.XML_NS, "space"),
"no xml:space (lookup value by name)");
assertEquals(AttributeSupport.getAttributeValue(badSpace, XMLConstants.XML_NS, "space"), "wibble",
@@ -375,82 +363,108 @@ public class AttributeSupportTest {
// getAttributeValueAsBoolean(Attribute)
// Use the previously tested AttributeSupport.getAttribute
- assertNull(AttributeSupport.getAttributeValueAsBoolean(null), "null attribute should be null");
- assertNull(AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"\" should be null");
- Boolean flag = AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrZero")));
+ Attr reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getAttributeValueAsBoolean(reqAttr), "\"\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrZero"));
+ assert reqAttr != null;
+ Boolean flag = AttributeSupport.getAttributeValueAsBoolean(reqAttr);
assert flag != null;
assertFalse(flag, "0 should be false");
-
- flag = AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrOne")));
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrOne"));
+ assert reqAttr != null;
+ flag = AttributeSupport.getAttributeValueAsBoolean(reqAttr);
assert flag != null;
assertTrue(flag, "1 should be true");
- assertNull(AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrThree"))), "2 should be null");
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrTwo"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getAttributeValueAsBoolean(reqAttr), "2 should be null");
- flag = AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrFalse")));
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrFalse"));
+ assert reqAttr != null;
+ flag = AttributeSupport.getAttributeValueAsBoolean(reqAttr);
assert flag != null;
assertFalse(flag, "false should be false");
- flag = AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrTrue")));
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrTrue"));
+ assert reqAttr != null;
+ flag = AttributeSupport.getAttributeValueAsBoolean(reqAttr);
assert flag != null;
assertTrue(flag, "true should be true");
- assertNull(AttributeSupport.getAttributeValueAsBoolean(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrTrueCaps"))), "TRUE should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrTrueCaps"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getAttributeValueAsBoolean(reqAttr), "TRUE should be null");
// getAttributeValueAsList(Attribute)
// Use the previously tested AttributeSupport.getAttribute
- assertTrue(AttributeSupport.getAttributeValueAsList(null).isEmpty(),
- "null attribute should give empty list");
- assertTrue(
- AttributeSupport.getAttributeValueAsList(
- AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"))).isEmpty(),
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertTrue(AttributeSupport.getAttributeValueAsList(reqAttr).isEmpty(),
"\"\" attribute should give empty list");
- assertEquals(AttributeSupport.getAttributeValueAsList(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrZero"))), Arrays.asList("0"), "attribute called testAttrZero");
- assertEquals(AttributeSupport.getAttributeValueAsList(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrList"))), Arrays.asList("0", "1", "2", "3", "4", "5", "6"),
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrZero"));
+ assert reqAttr != null;
+ assertEquals(AttributeSupport.getAttributeValueAsList(reqAttr), Arrays.asList("0"), "attribute called testAttrZero");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrList"));
+ assert reqAttr != null;
+ assertEquals(AttributeSupport.getAttributeValueAsList(reqAttr), Arrays.asList("0", "1", "2", "3", "4", "5", "6"),
"attribute called testAttrList");
// getAttributeValueAsQName(Attribute)
// Use the previously tested AttributeSupport.getAttribute
- assertNull(AttributeSupport.getAttributeValueAsQName(null), "null attribute should be null");
- assertNull(AttributeSupport.getAttributeValueAsQName(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"\" should be null");
- assertEquals(AttributeSupport.getAttributeValueAsQName(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrQName"))), idAttrQName, "attribute called testAttrQName");
- assertEquals(AttributeSupport.getAttributeValueAsQName(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrZero"))), new QName("0"), "attribute called testAttrZero");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getAttributeValueAsQName(reqAttr), "\"\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrQName"));
+ assert reqAttr != null;
+ assertEquals(AttributeSupport.getAttributeValueAsQName(reqAttr), idAttrQName, "attribute called testAttrQName");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrZero"));
+ assert reqAttr != null;
+ assertEquals(AttributeSupport.getAttributeValueAsQName(reqAttr), new QName("0"), "attribute called testAttrZero");
// getDateTimeAttribute
// Use the previously tested AttributeSupport.getAttribute
- assertNull(AttributeSupport.getDateTimeAttribute(null), "null attribute should be null");
- assertNull(AttributeSupport.getDateTimeAttribute(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"\" should be null");
- assertNull(AttributeSupport.getDateTimeAttribute(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"0\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getDateTimeAttribute(reqAttr), "\"\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getDateTimeAttribute(reqAttr), "\"0\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEpochPlusOneSec"));
+ assert reqAttr != null;
assertEquals(
- AttributeSupport.getDateTimeAttribute(
- AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEpochPlusOneSec"))),
+ AttributeSupport.getDateTimeAttribute(reqAttr),
Instant.ofEpochSecond(1), "attribute called testAttrEpochPlusOneSec");
// getDurationAttributeValueAsLong
// Use the previously tested AttributeSupport.getAttribute
- assertNull(AttributeSupport.getDurationAttributeValue(null), "null attribute should be null");
- assertNull(AttributeSupport.getDurationAttributeValue(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"\" should be null");
- assertNull(AttributeSupport.getDurationAttributeValue(AttributeSupport.getAttribute(attributes,
- new QName(TEST_NS, "testAttrEmpty"))), "\"0\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getDurationAttributeValue(reqAttr), "\"\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrEmpty"));
+ assert reqAttr != null;
+ assertNull(AttributeSupport.getDurationAttributeValue(reqAttr), "\"0\" should be null");
+
+ reqAttr = AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrMinusOneDay"));
+ assert reqAttr != null;
assertEquals(
- AttributeSupport.getDurationAttributeValue(
- AttributeSupport.getAttribute(attributes, new QName(TEST_NS, "testAttrMinusOneDay"))),
- Duration.ofDays(-1), "attribute called testAttrMinusOneDay");
+ AttributeSupport.getDurationAttributeValue(reqAttr),
+ Duration.ofDays(-1), "attribute called testAttrMinusOneDay");
}
@Test(dependsOnMethods = {"testGetAttributeMethods", "testGetID"}) public void testAppends() {
@@ -630,7 +644,8 @@ public class AttributeSupportTest {
}
assertFalse(thrown, "All non nulls should not throw");
assertEquals(
- AttributeSupport.getDurationAttributeValue(AttributeSupport.getAttribute(createdElement, qName)),
+ AttributeSupport.getDurationAttributeValue(
+ Constraint.isNotNull(AttributeSupport.getAttribute(createdElement, qName), "NPE")),
duration, "getDurationAttributeValueAsLong failed");
// Construct a time that contains nothing below the level of milliseconds,
@@ -663,7 +678,8 @@ public class AttributeSupportTest {
}
assertFalse(thrown, "All non nulls should not throw");
assertEquals(
- AttributeSupport.getDateTimeAttribute(AttributeSupport.getAttribute(createdElement, qName)),
+ AttributeSupport.getDateTimeAttribute(
+ Constraint.isNotNull(AttributeSupport.getAttribute(createdElement, qName), "NPE")),
time, "getDurationAttributeValueAsLong failed");
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list