[java-shib-shared] 03/03: JSSH-29 Add a @NonnullBeforeTest annotation https://shibboleth.atlassian.net/browse/JSSH-29

Rod Widdowson rdw at steadingsoftware.com
Fri Apr 28 15:21:19 UTC 2023


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

rdw 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=9faf1b006e45feea8e9c2e09ddc700689e6fb768

commit 9faf1b006e45feea8e9c2e09ddc700689e6fb768
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Apr 28 16:21:08 2023 +0100

    JSSH-29 Add a @NonnullBeforeTest annotation
    https://shibboleth.atlassian.net/browse/JSSH-29
    
    Start to use the annotation
---
 .../shibboleth/shared/codec/Base64SupportTest.java    |  3 ++-
 .../AbstractIdentifiedInitializableComponentTest.java |  1 +
 .../shibboleth/shared/xml/AttributeSupportTest.java   | 17 +++++++++--------
 .../net/shibboleth/shared/xml/DOMTypeSupportTest.java | 19 ++++++++++---------
 .../net/shibboleth/shared/xml/ElementSupportTest.java | 10 ++++++----
 .../shibboleth/shared/xml/NamespaceSupportTest.java   |  9 +++++----
 .../net/shibboleth/shared/xml/QNameSupportTest.java   |  7 ++++---
 .../net/shibboleth/shared/xml/SchemaBuilderTest.java  |  6 ++++--
 .../shibboleth/shared/xml/SerializeSupportTest.java   |  5 +++--
 .../shibboleth/shared/xml/impl/WellFormedTest.java    |  3 ++-
 .../shared/testing/DatabaseTestingSupport.java        |  5 +++--
 11 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/shib-support/src/test/java/net/shibboleth/shared/codec/Base64SupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/codec/Base64SupportTest.java
index e5b0107e..f27b3bb4 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/codec/Base64SupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/codec/Base64SupportTest.java
@@ -23,6 +23,7 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.logic.ConstraintViolationException;
 
 /** {@link Base64Support} unit test. */
@@ -49,7 +50,7 @@ public class Base64SupportTest {
                     + "IHZlbGl0IGlhY3VsaXMgbWV0dXMsIHF1aXMgdnVscHV0YXRlIGRpYW0gcXVhbQ";
 
     //Inited below
-    private static byte[] PLAIN_BYTES;
+    @NonnullBeforeTest private static byte[] PLAIN_BYTES;
     
     private final static String UNCHUNCKED_ENCODED_BYTES = "FPucA9l+";
     
diff --git a/shib-support/src/test/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponentTest.java b/shib-support/src/test/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponentTest.java
index f4197564..799f6f72 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponentTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/component/AbstractIdentifiedInitializableComponentTest.java
@@ -30,6 +30,7 @@ public class AbstractIdentifiedInitializableComponentTest {
      * 
      * @throws Exception if something bad happens
      */
+    @SuppressWarnings("null")
     @Test public void testId() throws Exception {
         MockComponent component = new MockComponent();
         Assert.assertNull(component.getId());
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 dab14f2a..6747aad4 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
@@ -31,6 +31,7 @@ import javax.annotation.Nonnull;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
@@ -63,24 +64,24 @@ public class AttributeSupportTest {
     @Nonnull @NotEmpty private static final String TEST_ID_ATTRIBUTE_VALUE = "IDAttrVALUE";
 
     // Set up at start of all methods
-    private QName idAttrQName;
+    @NonnullBeforeTest private QName idAttrQName;
 
-    private Element goodBaseIdSpaceLang;
+    @NonnullBeforeTest private Element goodBaseIdSpaceLang;
 
-    private Element noBaseIdSpaceLang;
+    @NonnullBeforeTest private Element noBaseIdSpaceLang;
 
-    private Element badSpace;
+    @NonnullBeforeTest private Element badSpace;
 
-    private Element preserveSpace;
+    @NonnullBeforeTest private Element preserveSpace;
 
-    private Element attributes;
+    @NonnullBeforeTest private Element attributes;
 
-    private Element createdElement;
+    @NonnullBeforeTest private Element createdElement;
 
     // Reset before each method.
     private Document document;
 
-    private BasicParserPool parserPool;
+    @NonnullBeforeTest private BasicParserPool parserPool;
 
     @BeforeClass public void setUp() throws XMLParserException, ComponentInitializationException, SAXException,
             IOException {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/DOMTypeSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/DOMTypeSupportTest.java
index ca4eea1e..303b6bdf 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/DOMTypeSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/DOMTypeSupportTest.java
@@ -31,6 +31,7 @@ import org.testng.annotations.Test;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.xml.impl.BasicParserPool;
 
@@ -40,28 +41,28 @@ import net.shibboleth.shared.xml.impl.BasicParserPool;
 @SuppressWarnings("javadoc")
 public class DOMTypeSupportTest {
 
-    private ParserPool parserPool;
-    private Element xsStringXSITypeElement;
-    private Element noXSITypeElement;
+    @NonnullBeforeTest private ParserPool parserPool;
+    @NonnullBeforeTest private Element xsStringXSITypeElement;
+    @NonnullBeforeTest private Element noXSITypeElement;
     
     @BeforeClass public void setup() throws ComponentInitializationException, SAXException, IOException, XMLParserException {
-        BasicParserPool pool = new BasicParserPool();
+        final BasicParserPool pool = new BasicParserPool();
         pool.initialize();
         parserPool = pool;
         
-        DocumentBuilder builder = parserPool.getBuilder();
-        
+        final DocumentBuilder builder = parserPool.getBuilder();
+        assert builder!= null;
         try (final InputStream s = getClass().getResourceAsStream("/net/shibboleth/shared/xml/getXSIType.xml")) {
             xsStringXSITypeElement = (Element) builder.parse(s).getFirstChild();
+            assert xsStringXSITypeElement!=null;
         }
 
         try (final InputStream s = getClass().getResourceAsStream("/net/shibboleth/shared/xml/noXSIType.xml")) {
             noXSITypeElement = (Element) builder.parse(s).getFirstChild();
+            assert noXSITypeElement!=null;
         }
         
-        if (null != builder) {
-            parserPool.returnBuilder(builder);
-        }
+        parserPool.returnBuilder(builder);
     }
     
     
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/ElementSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/ElementSupportTest.java
index 6bc078ff..48b464bf 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/ElementSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/ElementSupportTest.java
@@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.ConstraintViolationException;
@@ -59,13 +60,13 @@ public class ElementSupportTest {
 
     @Nonnull private static final QName TEST_ELEMENT_QNAME = new QName(TEST_NS, TEST_ELEMENT_NAME, TEST_PREFIX);
 
-    private BasicParserPool parserPool;
+    @NonnullBeforeTest private BasicParserPool parserPool;
 
-    private Document testFileDocument;
+    @NonnullBeforeTest private Document testFileDocument;
 
-    private Document testerDocument;
+    @NonnullBeforeTest private Document testerDocument;
 
-    private Element rootElement;
+    @NonnullBeforeTest private Element rootElement;
 
     @BeforeClass public void setUp() throws XMLParserException, ComponentInitializationException, SAXException,
             IOException {
@@ -82,6 +83,7 @@ public class ElementSupportTest {
         } finally {
             parserPool.returnBuilder(builder);
         }
+        assert rootElement!=null && testerDocument!=null && testFileDocument!=null;
     }
 
     @Test public void testIsElementNamed() {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/NamespaceSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/NamespaceSupportTest.java
index 689a90e1..74b01332 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/NamespaceSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/NamespaceSupportTest.java
@@ -30,6 +30,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.xml.impl.BasicParserPool;
 
@@ -39,13 +40,13 @@ import net.shibboleth.shared.xml.impl.BasicParserPool;
 @SuppressWarnings("javadoc")
 public class NamespaceSupportTest {
 
-    private Element parent;
+    @NonnullBeforeTest private Element parent;
 
-    private Element child;
+    @NonnullBeforeTest private Element child;
 
-    private Element grandchild;
+    @NonnullBeforeTest private Element grandchild;
 
-    private BasicParserPool parserPool;
+    @NonnullBeforeTest private BasicParserPool parserPool;
 
     private static final String NAMESPACE_1 = "http://example.org/NameSpace1";
 
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/QNameSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/QNameSupportTest.java
index fe0c1a39..cba0f866 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/QNameSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/QNameSupportTest.java
@@ -24,6 +24,7 @@ import javax.annotation.Nonnull;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.ConstraintViolationException;
@@ -58,11 +59,11 @@ public class QNameSupportTest {
 
     @Nonnull @NotEmpty private static final String PREFIX_2 = "myns2";
 
-    private ParserPool parserPool;
+    @NonnullBeforeTest private ParserPool parserPool;
 
-    private Element parent;
+    @NonnullBeforeTest private Element parent;
 
-    private Element child;
+    @NonnullBeforeTest private Element child;
 
     @BeforeClass public void setup() throws ComponentInitializationException, SAXException, IOException,
             XMLParserException {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/SchemaBuilderTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/SchemaBuilderTest.java
index b7c60573..4ef6cc85 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/SchemaBuilderTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/SchemaBuilderTest.java
@@ -32,6 +32,7 @@ import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 import org.xml.sax.SAXException;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.component.ComponentInitializationException;
 
 /**
@@ -48,9 +49,9 @@ public class SchemaBuilderTest {
 
     private static final String SECOND_SCHEMA_FILE = "schemaBuilderTest-schemaSecondLoaded.xsd";
 
-    private URL works;
+    @NonnullBeforeTest private URL works;
 
-    private URL fails;
+    @NonnullBeforeTest private URL fails;
 
     private StreamSource workingSource() throws IOException {
         return new StreamSource(works.openStream());
@@ -63,6 +64,7 @@ public class SchemaBuilderTest {
     @BeforeClass public void setup()  {
         works = getClass().getResource(TEST_DIR + "schemaBuilderTest-works.xml");
         fails = getClass().getResource(TEST_DIR + "schemaBuilderTest-fails.xml");
+        assert works != null && fails != null;
     }
 
     @Test public void testFiles() throws SAXException, IOException {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/SerializeSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/SerializeSupportTest.java
index 280eeccf..e1a90aa1 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/SerializeSupportTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/SerializeSupportTest.java
@@ -41,6 +41,7 @@ import org.w3c.dom.ls.LSOutput;
 import org.w3c.dom.ls.LSSerializer;
 import org.xml.sax.SAXException;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.xml.impl.BasicParserPool;
 
@@ -50,9 +51,9 @@ import net.shibboleth.shared.xml.impl.BasicParserPool;
 @SuppressWarnings("javadoc")
 public class SerializeSupportTest {
 
-    private Element parent;
+    @NonnullBeforeTest private Element parent;
 
-    private BasicParserPool parserPool;
+    @NonnullBeforeTest private BasicParserPool parserPool;
 
     // Helper methods, from http://www.java2s.com/Code/Java/XML/ComparetwoDOMNodes.htm
     private int countNonNamespaceAttributes(final NamedNodeMap attrs) {
diff --git a/shib-support/src/test/java/net/shibboleth/shared/xml/impl/WellFormedTest.java b/shib-support/src/test/java/net/shibboleth/shared/xml/impl/WellFormedTest.java
index 6118f6dc..36a8f773 100644
--- a/shib-support/src/test/java/net/shibboleth/shared/xml/impl/WellFormedTest.java
+++ b/shib-support/src/test/java/net/shibboleth/shared/xml/impl/WellFormedTest.java
@@ -30,6 +30,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.ls.DOMImplementationLS;
 import org.xml.sax.SAXException;
 
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeTest;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.xml.XMLParserException;
 
@@ -38,7 +39,7 @@ import net.shibboleth.shared.xml.XMLParserException;
  */
 public class WellFormedTest {
 
-    private BasicParserPool parserPool;
+    @NonnullBeforeTest private BasicParserPool parserPool;
 
     @BeforeClass public void setup()
             throws XMLParserException, ComponentInitializationException, SAXException, IOException {
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/DatabaseTestingSupport.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/DatabaseTestingSupport.java
index 270962d7..ab1a29bd 100644
--- a/shib-testing/src/main/java/net/shibboleth/shared/testing/DatabaseTestingSupport.java
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/DatabaseTestingSupport.java
@@ -128,7 +128,7 @@ public final class DatabaseTestingSupport {
      * @param identifier a name to uniquify this database.
      * @return a DataSource which can then be used for testing.
      */
-    @Nonnull public static DataSource GetMockDataSource(final @Nullable String initializingSQLFile,
+    @Nonnull public static DataSource GetMockDataSource(final @Nonnull String initializingSQLFile,
             final @Nonnull String identifier) {
         return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:mem:" + identifier);
     }
@@ -139,7 +139,7 @@ public final class DatabaseTestingSupport {
      * @param server the server name and database name.  For instance "//localhost/testdb"
      * @return a DataSource which can then be used for testing
      */
-    @Nonnull public static DataSource GetDataSourceFromHsqlServer(final @Nullable String initializingSQLFile,
+    @Nonnull public static DataSource GetDataSourceFromHsqlServer(final @Nonnull String initializingSQLFile,
             final @Nonnull String server) {
         return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:hsql:" + server);
     }
@@ -152,6 +152,7 @@ public final class DatabaseTestingSupport {
      */
     public static void InitializeDataSourceFromFile(final String sqlFile, final DataSource source) {
         final String sql = ReadSqlFromFile(sqlFile);
+        assert sql != null;
         final String[] statements = sql.split(";");
         for (final String statement : statements) {
             ExecuteUpdate(statement.trim(), source);

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


More information about the commits mailing list