[java-shib-shared] 02/02: javadoc, code style, untabify

Rod Widdowson rdw at steadingsoftware.com
Thu Sep 29 15:05:46 UTC 2022


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=ef55fd26e029f66a24993701229b08305d12d3b1

commit ef55fd26e029f66a24993701229b08305d12d3b1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Sep 29 16:02:38 2022 +0100

    javadoc, code style, untabify
---
 .../shared/testing/DatabaseTestingSupport.java     | 34 +++++++++++++++-------
 .../shared/testing/MockReloadableService.java      |  1 +
 .../shared/testing/ResourceTestHelper.java         | 20 +++++--------
 3 files changed, 32 insertions(+), 23 deletions(-)

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 02dce549..0e3e03de 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
@@ -41,6 +41,7 @@ import net.shibboleth.shared.primitive.StringSupport;
  */
 public class DatabaseTestingSupport {
 
+    /** Logger. */
     @Nonnull static Logger log = LoggerFactory.getLogger(DatabaseTestingSupport.class);
     
     /**
@@ -49,7 +50,7 @@ public class DatabaseTestingSupport {
      * @param initializingSQLFile path to SQL to run at init time
      * @param source the data source
      */
-    public static void InitializeDataSource(@Nullable String initializingSQLFile, DataSource source) {
+    public static void InitializeDataSource(final @Nullable String initializingSQLFile, final DataSource source) {
 
         final String sql = ReadSqlFromFile(initializingSQLFile);
         if (sql == null) {
@@ -58,7 +59,11 @@ public class DatabaseTestingSupport {
         ExecuteUpdate(sql, source);
     }
 
-    protected static String ReadSqlFromFile(@Nullable String initializingSQLFile) {
+    /** Read some SQL from a file
+     * @param initializingSQLFile the file name
+     * @return the data
+     */
+    protected static String ReadSqlFromFile(final @Nullable String initializingSQLFile) {
 
         final String file = StringSupport.trimOrNull(initializingSQLFile);
 
@@ -88,13 +93,17 @@ public class DatabaseTestingSupport {
         return sql;
     }
 
-    protected static void ExecuteUpdate(@Nullable String sql, DataSource source) {
+    /** Execute an SQP update
+     * @param sql what to execute
+     * @param source what to executer it on
+     */
+    protected static void ExecuteUpdate(final @Nullable String sql, final DataSource source) {
 
         log.debug("Applying SQL: \n {}", sql);
 
         try {
-            Connection dbConn = source.getConnection();
-            Statement statement = dbConn.createStatement();
+            final Connection dbConn = source.getConnection();
+            final Statement statement = dbConn.createStatement();
 
             statement.executeUpdate(sql);
         } catch (SQLException e) {
@@ -111,7 +120,7 @@ public class DatabaseTestingSupport {
      * @param identifier a name to uniquify this database.
      * @return a DataSource which can then be used for testing.
      */
-    public static DataSource GetMockDataSource(@Nullable String initializingSQLFile, @Nonnull String identifier) {
+    public static DataSource GetMockDataSource(final @Nullable String initializingSQLFile, final @Nonnull String identifier) {
 
         return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:mem:" + identifier);
     }
@@ -122,7 +131,7 @@ public class DatabaseTestingSupport {
      * @param server the server name and database name.  For instance "//localhost/testdb"
      * @return a DataSource which can then be used for testing
      */
-    public static DataSource GetDataSourceFromHsqlServer(@Nullable String initializingSQLFile, @Nonnull String server) {
+    public static DataSource GetDataSourceFromHsqlServer(final @Nullable String initializingSQLFile, final @Nonnull String server) {
 
         return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:hsql:" + server);
     }
@@ -133,7 +142,7 @@ public class DatabaseTestingSupport {
      * @param sqlFile path to file containing multiple SQL statements separated by semicolons.
      * @param source data source
      */
-    public static void InitializeDataSourceFromFile(String sqlFile, DataSource source) {
+    public static void InitializeDataSourceFromFile(final String sqlFile, final DataSource source) {
         final String sql = ReadSqlFromFile(sqlFile);
         final String[] statements = sql.split(";");
         for (String statement : statements) {
@@ -141,7 +150,12 @@ public class DatabaseTestingSupport {
         }
     }
 
-    protected static DataSource GetDataSourceFromUrl(String initializingSQLFile, String JdbcUri) {
+    /** Createa data source from a provided URL
+     * @param initializingSQLFile what to initialize with
+     * @param JdbcUri the URI
+     * @return the {@link DataSource}
+     */
+    protected static DataSource GetDataSourceFromUrl(final String initializingSQLFile, final String JdbcUri) {
         JDBCDataSource jdbcSource = new JDBCDataSource();
 
         jdbcSource.setUrl(JdbcUri);
@@ -153,4 +167,4 @@ public class DatabaseTestingSupport {
         return jdbcSource;
     }
 
-}
\ No newline at end of file
+}
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
index dfb6ca1f..62fb2259 100644
--- a/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/MockReloadableService.java
@@ -30,6 +30,7 @@ import net.shibboleth.shared.service.ServiceableComponent;
  */
 public class MockReloadableService<T> extends AbstractReloadableService<T> {
 
+    /** The component we are presenting to provide. */
     @Nonnull private final ServiceableComponent<T> component;
 
     /**
diff --git a/shib-testing/src/main/java/net/shibboleth/shared/testing/ResourceTestHelper.java b/shib-testing/src/main/java/net/shibboleth/shared/testing/ResourceTestHelper.java
index 16be6d36..4d30aae2 100644
--- a/shib-testing/src/main/java/net/shibboleth/shared/testing/ResourceTestHelper.java
+++ b/shib-testing/src/main/java/net/shibboleth/shared/testing/ResourceTestHelper.java
@@ -22,21 +22,21 @@ import java.io.InputStream;
 
 import org.springframework.core.io.Resource;
 
-import com.google.common.io.Closeables;
-
 /**
  * Compare two resources for equality.
  * 
  * <p>NOTE: If this changes, change the "additional" copy in shib-spring.</p>
  */
- at SuppressWarnings("javadoc")
 public class ResourceTestHelper {
 
+    /** Compare to see whether the content of two resources are the same
+     * @param first Resource to compare
+     * @param second  Resource to compare
+     * @return whether They are equal
+     * @throws IOException if a read fails
+     */
     static public boolean compare(final Resource first, final Resource second) throws IOException {
-        final InputStream firstStream = first.getInputStream();
-        final InputStream secondStream = second.getInputStream();
-
-        try {
+        try (final InputStream firstStream = first.getInputStream(); final InputStream secondStream = second.getInputStream()) {
             while (true) {
 
                 // Remove any differences based on CRLF handling
@@ -48,19 +48,13 @@ public class ResourceTestHelper {
                 while (secondInt == 10 || secondInt == 13) {
                     secondInt = secondStream.read();
                 }
-
                 if (firstInt == -1) {
                     return secondInt == -1;
                 }
-
                 if (firstInt != secondInt) {
                     return false;
                 }
             }
-        } finally {
-            Closeables.close(firstStream, true);
-            Closeables.close(secondStream, true);
         }
     }
-
 }

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


More information about the commits mailing list