diff --git a/src/main/java/org/utplsql/api/DBHelper.java b/src/main/java/org/utplsql/api/DBHelper.java index 3c386cb..7f3bee4 100644 --- a/src/main/java/org/utplsql/api/DBHelper.java +++ b/src/main/java/org/utplsql/api/DBHelper.java @@ -1,7 +1,6 @@ package org.utplsql.api; import oracle.jdbc.OracleTypes; -import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.UtPLSQLNotInstalledException; import java.sql.*; diff --git a/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java b/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java index 0e992cf..57afa30 100644 --- a/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java +++ b/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java @@ -18,6 +18,8 @@ */ public class EnvironmentVariableUtil { + private EnvironmentVariableUtil() {} + /** * Returns the value for a given key from environment (see class description) * @@ -43,4 +45,6 @@ public static String getEnvValue(String key, String defaultValue) { return val; } + + } diff --git a/src/main/java/org/utplsql/api/FileMapper.java b/src/main/java/org/utplsql/api/FileMapper.java index cdea084..8fae53f 100644 --- a/src/main/java/org/utplsql/api/FileMapper.java +++ b/src/main/java/org/utplsql/api/FileMapper.java @@ -20,7 +20,7 @@ public static Array buildFileMappingArray( Connection conn, FileMapperOptions mapperOptions) throws SQLException { OracleConnection oraConn = conn.unwrap(OracleConnection.class); - Map typeMap = conn.getTypeMap(); + Map> typeMap = conn.getTypeMap(); typeMap.put(CustomTypes.UT_FILE_MAPPING, FileMapping.class); typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class); conn.setTypeMap(typeMap); diff --git a/src/main/java/org/utplsql/api/FileMapping.java b/src/main/java/org/utplsql/api/FileMapping.java index eb383dd..30a9d8e 100644 --- a/src/main/java/org/utplsql/api/FileMapping.java +++ b/src/main/java/org/utplsql/api/FileMapping.java @@ -17,11 +17,18 @@ public class FileMapping implements SQLData { public FileMapping() {} + public FileMapping(String fileName, String objectOwner, String objectName, String objectType) { + this.fileName = fileName; + this.objectOwner = objectOwner; + this.objectName = objectName; + this.objectType = objectType; + } + public String getFileName() { return fileName; } - public void setFileName(String fileName) { + private void setFileName(String fileName) { this.fileName = fileName; } @@ -29,7 +36,7 @@ public String getObjectOwner() { return objectOwner; } - public void setObjectOwner(String objectOwner) { + private void setObjectOwner(String objectOwner) { this.objectOwner = objectOwner; } @@ -37,7 +44,7 @@ public String getObjectName() { return objectName; } - public void setObjectName(String objectName) { + private void setObjectName(String objectName) { this.objectName = objectName; } @@ -45,7 +52,7 @@ public String getObjectType() { return objectType; } - public void setObjectType(String objectType) { + private void setObjectType(String objectType) { this.objectType = objectType; } diff --git a/src/main/java/org/utplsql/api/JavaApiVersionInfo.java b/src/main/java/org/utplsql/api/JavaApiVersionInfo.java index f4727c5..bca302f 100644 --- a/src/main/java/org/utplsql/api/JavaApiVersionInfo.java +++ b/src/main/java/org/utplsql/api/JavaApiVersionInfo.java @@ -7,6 +7,8 @@ */ public class JavaApiVersionInfo { + private JavaApiVersionInfo() { } + private static final String BUILD_NO = "123"; private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api"; private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT"; diff --git a/src/main/java/org/utplsql/api/KeyValuePair.java b/src/main/java/org/utplsql/api/KeyValuePair.java index 5826f45..04be4cf 100644 --- a/src/main/java/org/utplsql/api/KeyValuePair.java +++ b/src/main/java/org/utplsql/api/KeyValuePair.java @@ -22,18 +22,10 @@ public String getKey() { return key; } - public void setKey(String key) { - this.key = key; - } - public String getValue() { return value; } - public void setValue(String value) { - this.value = value; - } - @Override public String getSQLTypeName() throws SQLException { return CustomTypes.UT_KEY_VALUE_PAIR; @@ -41,19 +33,19 @@ public String getSQLTypeName() throws SQLException { @Override public void readSQL(SQLInput stream, String typeName) throws SQLException { - setKey(stream.readString()); - setValue(stream.readString()); + key = stream.readString(); + value = stream.readString(); } @Override public void writeSQL(SQLOutput stream) throws SQLException { - stream.writeString(getKey()); - stream.writeString(getValue()); + stream.writeString(key); + stream.writeString(value); } @Override public String toString() { - return String.format("%s => %s", getKey(), getValue()); + return String.format("%s => %s", key, value); } } diff --git a/src/main/java/org/utplsql/api/ResourceUtil.java b/src/main/java/org/utplsql/api/ResourceUtil.java index d3b7f48..e8bbbc4 100644 --- a/src/main/java/org/utplsql/api/ResourceUtil.java +++ b/src/main/java/org/utplsql/api/ResourceUtil.java @@ -21,6 +21,8 @@ */ public class ResourceUtil { + private ResourceUtil() {} + /** * Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system * diff --git a/src/main/java/org/utplsql/api/TestRunner.java b/src/main/java/org/utplsql/api/TestRunner.java index 9344abe..0473683 100644 --- a/src/main/java/org/utplsql/api/TestRunner.java +++ b/src/main/java/org/utplsql/api/TestRunner.java @@ -1,6 +1,5 @@ package org.utplsql.api; -import oracle.jdbc.OracleConnection; import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; @@ -10,7 +9,6 @@ import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.api.testRunner.TestRunnerStatement; -import java.sql.CallableStatement; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -24,10 +22,10 @@ */ public class TestRunner { - private TestRunnerOptions options = new TestRunnerOptions(); + private final TestRunnerOptions options = new TestRunnerOptions(); private CompatibilityProxy compatibilityProxy; private ReporterFactory reporterFactory; - private List reporterNames = new ArrayList<>(); + private final List reporterNames = new ArrayList<>(); public TestRunner addPath(String path) { options.pathList.add(path); @@ -35,7 +33,7 @@ public TestRunner addPath(String path) { } public TestRunner addPathList(List paths) { - if (options.pathList != null) options.pathList.addAll(paths); + options.pathList.addAll(paths); return this; } @@ -115,7 +113,7 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) { private void delayedAddReporters() { if ( reporterFactory != null ) - reporterNames.stream().forEach( this::addReporter ); + reporterNames.forEach( this::addReporter ); else throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!"); } @@ -142,13 +140,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException, options.reporterList.add(new DocumentationReporter().init(conn)); } - TestRunnerStatement testRunnerStatement = null; - - try { - DBHelper.enableDBMSOutput(conn); - - testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn); - + DBHelper.enableDBMSOutput(conn); + try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) { testRunnerStatement.execute(); } catch (SQLException e) { if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) { @@ -161,10 +154,6 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { throw e; } } finally { - if (testRunnerStatement != null) { - testRunnerStatement.close(); - } - DBHelper.disableDBMSOutput(conn); } } diff --git a/src/main/java/org/utplsql/api/TestRunnerOptions.java b/src/main/java/org/utplsql/api/TestRunnerOptions.java index b82d898..936254f 100644 --- a/src/main/java/org/utplsql/api/TestRunnerOptions.java +++ b/src/main/java/org/utplsql/api/TestRunnerOptions.java @@ -3,7 +3,6 @@ import org.utplsql.api.reporter.Reporter; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -12,14 +11,14 @@ * @author pesse */ public class TestRunnerOptions { - public List pathList = new ArrayList<>(); - public List reporterList = new ArrayList<>(); + public final List pathList = new ArrayList<>(); + public final List reporterList = new ArrayList<>(); public boolean colorConsole = false; - public List coverageSchemes = new ArrayList<>(); - public List sourceFiles = new ArrayList<>(); - public List testFiles = new ArrayList<>(); - public List includeObjects = new ArrayList<>(); - public List excludeObjects = new ArrayList<>(); + public final List coverageSchemes = new ArrayList<>(); + public final List sourceFiles = new ArrayList<>(); + public final List testFiles = new ArrayList<>(); + public final List includeObjects = new ArrayList<>(); + public final List excludeObjects = new ArrayList<>(); public FileMapperOptions sourceMappingOptions; public FileMapperOptions testMappingOptions; public boolean failOnErrors = false; diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index afaeee4..b2b802a 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -10,44 +10,52 @@ * @author pesse */ public class Version implements Comparable { - private String origString; - private Integer major; - private Integer minor; - private Integer bugfix; - private Integer build; - private boolean valid = false; + private final String origString; + private final Integer major; + private final Integer minor; + private final Integer bugfix; + private final Integer build; + private final boolean valid; public Version( String versionString ) { assert versionString != null; - this.origString = versionString; - parseVersionString(); - } + this.origString = versionString.trim(); - private void parseVersionString() - { Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?"); Matcher m = p.matcher(origString); + Integer major = null; + Integer minor = null; + Integer bugfix = null; + Integer build = null; + boolean valid = false; + try { if (m.find()) { - if ( m.group(1) != null ) + if (m.group(1) != null ) major = Integer.valueOf(m.group(1)); - if ( m.group(2) != null ) + if (m.group(2) != null ) minor = Integer.valueOf(m.group(2)); - if ( m.group(3) != null ) + if (m.group(3) != null ) bugfix = Integer.valueOf(m.group(3)); - if ( m.group(4) != null ) + if (m.group(4) != null ) build = Integer.valueOf(m.group(4)); - if ( major != null ) // We need a valid major version as minimum requirement for a Version object to be valid - valid = true; + // We need a valid major version as minimum requirement for a Version object to be valid + valid = major != null; } } catch ( NumberFormatException e ) { valid = false; } + + this.major = major; + this.minor = minor; + this.bugfix = bugfix; + this.build = build; + this.valid = valid; } @Override @@ -85,11 +93,11 @@ public String getNormalizedString() StringBuilder sb = new StringBuilder(); sb.append(String.valueOf(major)); if ( minor != null ) - sb.append("." + String.valueOf(minor)); + sb.append(".").append(String.valueOf(minor)); if ( bugfix != null ) - sb.append("." + String.valueOf(bugfix)); + sb.append(".").append(String.valueOf(bugfix)); if ( build != null ) - sb.append("." + String.valueOf(build)); + sb.append(".").append(String.valueOf(build)); return sb.toString(); } @@ -152,10 +160,7 @@ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException versionsAreValid(v); - if ( compareTo(v) >= 0 ) - return true; - else - return false; + return compareTo(v) >= 0; } @@ -163,10 +168,7 @@ public boolean isGreaterThan( Version v) throws InvalidVersionException { versionsAreValid(v); - if ( compareTo(v) > 0 ) - return true; - else - return false; + return compareTo(v) > 0; } public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException @@ -174,19 +176,13 @@ public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException versionsAreValid(v); - if ( compareTo(v) <= 0 ) - return true; - else - return false; + return compareTo(v) <= 0; } public boolean isLessThan( Version v) throws InvalidVersionException { versionsAreValid(v); - if ( compareTo(v) < 0 ) - return true; - else - return false; + return compareTo(v) < 0; } } diff --git a/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java b/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java index 0caad21..4f3da3b 100644 --- a/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java +++ b/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java @@ -79,9 +79,7 @@ private void doExpectCompatibility() */ private boolean versionCompatibilityCheck(Connection conn, String requested, String current) throws SQLException { - CallableStatement callableStatement = null; - try { - callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;"); + try(CallableStatement callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;")) { callableStatement.registerOutParameter(1, Types.SMALLINT); callableStatement.setString(2, requested); @@ -97,9 +95,6 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str return false; else throw e; - } finally { - if (callableStatement != null) - callableStatement.close(); } } @@ -108,11 +103,11 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str * @param requested * @return */ - private boolean versionCompatibilityCheckPre303( String requested ) + private boolean versionCompatibilityCheckPre303(String requested ) { Version requesteVersion = new Version(requested); - if ( databaseVersion.getMajor() == requesteVersion.getMajor() && (requesteVersion.getMinor() == null || databaseVersion.getMinor() == requesteVersion.getMinor()) ) + if (databaseVersion.getMajor().equals(requesteVersion.getMajor()) && (requesteVersion.getMinor() == null || requesteVersion.getMinor().equals(databaseVersion.getMinor())) ) return true; else return false; diff --git a/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java b/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java index 08d6546..5f0b629 100644 --- a/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java +++ b/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java @@ -12,26 +12,20 @@ public enum OptionalFeatures { FRAMEWORK_COMPATIBILITY_CHECK("3.0.3", null), CUSTOM_REPORTERS("3.1.0", null); - private Version minVersion; - private Version maxVersion; + private final Version minVersion; + private final Version maxVersion; OptionalFeatures( String minVersion, String maxVersion ) { - if ( minVersion != null ) - this.minVersion = new Version(minVersion); - if ( maxVersion != null) - this.maxVersion = new Version(maxVersion); + this.minVersion = minVersion != null ? new Version(minVersion) : null; + this.maxVersion = maxVersion != null ? new Version(maxVersion) : null; } public boolean isAvailableFor(Version version ) { try { - if ((minVersion == null || version.isGreaterOrEqualThan(minVersion)) && - (maxVersion == null || maxVersion.isGreaterOrEqualThan(version)) - ) - return true; - else - return false; + return (minVersion == null || version.isGreaterOrEqualThan(minVersion)) && + (maxVersion == null || maxVersion.isGreaterOrEqualThan(version)); } catch ( InvalidVersionException e ) { return false; // We have no optional features for invalid versions } diff --git a/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java b/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java index 5d944d6..b3734ca 100644 --- a/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java +++ b/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java @@ -1,6 +1,5 @@ package org.utplsql.api.exception; -import org.utplsql.api.DBHelper; import org.utplsql.api.Version; import org.utplsql.api.compatibility.CompatibilityProxy; @@ -13,8 +12,8 @@ */ public class DatabaseNotCompatibleException extends SQLException { - private Version clientVersion; - private Version databaseVersion; + private final Version clientVersion; + private final Version databaseVersion; public DatabaseNotCompatibleException( String message, Version clientVersion, Version databaseVersion, Throwable cause ) { diff --git a/src/main/java/org/utplsql/api/exception/InvalidVersionException.java b/src/main/java/org/utplsql/api/exception/InvalidVersionException.java index f9a6d59..49942ae 100644 --- a/src/main/java/org/utplsql/api/exception/InvalidVersionException.java +++ b/src/main/java/org/utplsql/api/exception/InvalidVersionException.java @@ -7,7 +7,7 @@ * @author pesse */ public class InvalidVersionException extends Exception { - private Version version; + private final Version version; public InvalidVersionException( Version version ) { this( version, null ); diff --git a/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java index 4dac3a4..53d4182 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java @@ -19,7 +19,7 @@ */ abstract class AbstractOutputBuffer implements OutputBuffer { - private Reporter reporter; + private final Reporter reporter; private int fetchSize = 100; /** diff --git a/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java index 4279e9c..e1cdeea 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java @@ -15,7 +15,7 @@ */ class NonOutputBuffer implements OutputBuffer { - private Reporter reporter; + private final Reporter reporter; NonOutputBuffer( Reporter reporter) { this.reporter = reporter; diff --git a/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java b/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java index 6f72d73..1f4bb9c 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java +++ b/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java @@ -34,7 +34,7 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re } } } - catch ( InvalidVersionException e ) { } + catch ( InvalidVersionException ignored ) { } // If we couldn't find an appropriate OutputBuffer, return the Pre310-Compatibility-Buffer return new CompatibilityOutputBufferPre310(reporter); @@ -52,14 +52,15 @@ private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) if ( isReporterResult == null ) throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!"); - else if (isReporterResult.equalsIgnoreCase("Y") ) - return true; else - return false; + return isReporterResult.equalsIgnoreCase("Y"); } else throw new SQLException("Could not check Reporter validity"); } } } + + private OutputBufferProvider() { + } } diff --git a/src/main/java/org/utplsql/api/reporter/CoreReporters.java b/src/main/java/org/utplsql/api/reporter/CoreReporters.java index e3e979f..c008fd5 100644 --- a/src/main/java/org/utplsql/api/reporter/CoreReporters.java +++ b/src/main/java/org/utplsql/api/reporter/CoreReporters.java @@ -19,8 +19,8 @@ public enum CoreReporters { UT_SONAR_TEST_REPORTER(new Version("3.0.0"), null), UT_COVERAGE_COBERTURA_REPORTER(new Version("3.1.0"), null); - private Version since; - private Version until; + private final Version since; + private final Version until; CoreReporters(Version since, Version until ) { this.since = since; @@ -46,7 +46,7 @@ public boolean isAvailableFor( Version databaseVersion ) { && (until == null || databaseVersion.isLessOrEqualThan(until))) return true; } - catch ( InvalidVersionException e ) { } + catch ( InvalidVersionException ignored ) { } return false; } diff --git a/src/main/java/org/utplsql/api/reporter/ReporterFactory.java b/src/main/java/org/utplsql/api/reporter/ReporterFactory.java index 8e9fb4b..17662d5 100644 --- a/src/main/java/org/utplsql/api/reporter/ReporterFactory.java +++ b/src/main/java/org/utplsql/api/reporter/ReporterFactory.java @@ -30,11 +30,11 @@ public ReporterFactoryMethodInfo(BiFunction factoryMethod; - public String description; + public final BiFunction factoryMethod; + public final String description; } - private Map reportFactoryMethodMap = new HashMap<>(); + private final Map reportFactoryMethodMap = new HashMap<>(); ReporterFactory() { } diff --git a/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java b/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java index e3de717..11a8798 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java @@ -3,36 +3,15 @@ import org.utplsql.api.reporter.ReporterFactory; import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; abstract class AbstractReporterInspector implements ReporterInspector { - protected ReporterFactory reporterFactory; - protected Connection connection; - protected Set infos; + protected final ReporterFactory reporterFactory; + protected final Connection connection; - AbstractReporterInspector(ReporterFactory reporterFactory, Connection conn ) throws SQLException { + AbstractReporterInspector(ReporterFactory reporterFactory, Connection conn ) { this.reporterFactory = reporterFactory; this.connection = conn; - - load(); - } - - protected abstract void load() throws SQLException; - - @Override - public Map getReporterInfoMap() { - return infos.stream().collect(Collectors.toMap(ReporterInfo::getName, i -> i)); - } - - @Override - public List getReporterInfos() { - return new ArrayList<>(infos); } } diff --git a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java index c6fc2c0..a987bdd 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java @@ -10,9 +10,9 @@ public enum Type { SQL, JAVA, SQL_WITH_JAVA } - private String name; - private Type type; - private String description; + private final String name; + private final Type type; + private final String description; ReporterInfo( String name, Type type, String description ) { this.name = name; diff --git a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java index d8169df..f539160 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java @@ -9,6 +9,8 @@ import java.sql.SQLException; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; /** * Gives information about available reporters @@ -19,7 +21,9 @@ public interface ReporterInspector { List getReporterInfos(); - Map getReporterInfoMap(); + default Map getReporterInfoMap() { + return getReporterInfos().stream().collect(Collectors.toMap(ReporterInfo::getName, Function.identity())); + } /** * Returns a new instance of a ReporterInspector, based on the utPLSQL version used in the connection diff --git a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java index b462ecc..cd1b8ea 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java @@ -4,7 +4,6 @@ import oracle.jdbc.OracleConnection; import oracle.jdbc.OracleType; import org.utplsql.api.compatibility.CompatibilityProxy; -import org.utplsql.api.reporter.CoreReporters; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; @@ -13,7 +12,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; -import java.util.stream.Collectors; /** ReporterInspector for v3.1.0 upwards * @@ -21,31 +19,30 @@ */ class ReporterInspector310 extends AbstractReporterInspector { - - private Map registeredReporterFactoryMethods; - private CompatibilityProxy compatibilityProxy; + private final Map registeredReporterFactoryMethods; + private final Set infos; ReporterInspector310(ReporterFactory reporterFactory, Connection conn ) throws SQLException { super(reporterFactory, conn); - } - - @Override - protected void load() throws SQLException { - registeredReporterFactoryMethods = reporterFactory.getRegisteredReporterInfo(); - compatibilityProxy = new CompatibilityProxy(connection); - - infos = new HashSet<>(); + Set reporterInfos = new HashSet<>(); try (PreparedStatement stmt = connection.prepareStatement("select * from table(ut_runner.get_reporters_list) order by 1")) { try (ResultSet rs = stmt.executeQuery() ) { while (rs.next()) - infos.add(getReporterInfo(rs.getString(1))); + reporterInfos.add(getReporterInfo(rs.getString(1))); } } + this.infos = reporterInfos; + + } + + @Override + public List getReporterInfos() { + return new ArrayList<>(infos); } - private ReporterInfo getReporterInfo( String reporterNameWithOwner ) throws SQLException { + private ReporterInfo getReporterInfo(String reporterNameWithOwner ) throws SQLException { String reporterName = reporterNameWithOwner.substring(reporterNameWithOwner.indexOf(".")+1).toUpperCase(); ReporterInfo.Type type = ReporterInfo.Type.SQL; @@ -60,6 +57,7 @@ private ReporterInfo getReporterInfo( String reporterNameWithOwner ) throws SQLE } private String getDescription( String reporterName ) throws SQLException { + CompatibilityProxy compatibilityProxy = new CompatibilityProxy(connection); Reporter reporter = reporterFactory.createReporter(reporterName).init(connection, compatibilityProxy, reporterFactory); OracleConnection oraCon = connection.unwrap(OracleConnection.class); diff --git a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspectorPre310.java b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspectorPre310.java index 5909708..f188ac9 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspectorPre310.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspectorPre310.java @@ -7,23 +7,28 @@ import java.sql.Connection; import java.sql.SQLException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; class ReporterInspectorPre310 extends AbstractReporterInspector { - private Map registeredReporterFactoryMethods; - private Map descriptions; + private final Map registeredReporterFactoryMethods; + private final Map descriptions = new HashMap<>(); + private final Set infos; - ReporterInspectorPre310(ReporterFactory reporterFactory, Connection conn ) throws SQLException { + ReporterInspectorPre310(ReporterFactory reporterFactory, Connection conn) throws SQLException { super(reporterFactory, conn); + registeredReporterFactoryMethods = reporterFactory.getRegisteredReporterInfo(); + initDefaultDescriptions(); + + Version databaseVersion = new CompatibilityProxy(connection).getDatabaseVersion(); + this.infos = Arrays.stream(CoreReporters.values()) + .filter(r -> r.isAvailableFor(databaseVersion)) + .map(this::getReporterInfo) + .collect(Collectors.toSet()); } private void initDefaultDescriptions() { - descriptions = new HashMap<>(); descriptions.put(CoreReporters.UT_COVERAGE_HTML_REPORTER, ""); descriptions.put(CoreReporters.UT_COVERAGE_SONAR_REPORTER, ""); descriptions.put(CoreReporters.UT_COVERALLS_REPORTER, ""); @@ -34,26 +39,20 @@ private void initDefaultDescriptions() { } @Override - protected void load() throws SQLException { - initDefaultDescriptions(); - Version databaseVersion = new CompatibilityProxy(connection).getDatabaseVersion(); - registeredReporterFactoryMethods = reporterFactory.getRegisteredReporterInfo(); - infos = Arrays.stream(CoreReporters.values()) - .filter(r -> r.isAvailableFor(databaseVersion)) - .map(this::getReporterInfo) - .collect(Collectors.toSet()); + public List getReporterInfos() { + return new ArrayList<>(this.infos); } - private ReporterInfo getReporterInfo( CoreReporters reporter ) { + private ReporterInfo getReporterInfo(CoreReporters reporter) { ReporterInfo.Type type = ReporterInfo.Type.SQL; String description = descriptions.get(reporter); - if ( registeredReporterFactoryMethods.containsKey(reporter.name()) ) { + if (registeredReporterFactoryMethods.containsKey(reporter.name())) { type = ReporterInfo.Type.SQL_WITH_JAVA; description += "\n" + registeredReporterFactoryMethods.get(reporter.name()); } - return new ReporterInfo( reporter.name(), type, description); + return new ReporterInfo(reporter.name(), type, description); } } diff --git a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java index 925d48d..a16437e 100644 --- a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java @@ -1,8 +1,10 @@ package org.utplsql.api.testRunner; import oracle.jdbc.OracleConnection; -import org.utplsql.api.*; -import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.CustomTypes; +import org.utplsql.api.FileMapper; +import org.utplsql.api.FileMapping; +import org.utplsql.api.TestRunnerOptions; import java.sql.CallableStatement; import java.sql.Connection; @@ -10,21 +12,24 @@ import java.sql.Types; import java.util.List; -/** Abstract class which creates a callable statement for running tests +/** + * Abstract class which creates a callable statement for running tests * The SQL to be used has to be implemented for there are differences between the Framework-versions * * @author pesse */ abstract class AbstractTestRunnerStatement implements TestRunnerStatement { - protected TestRunnerOptions options; - protected Connection conn; - protected CallableStatement callableStatement; + protected final TestRunnerOptions options; + protected final Connection conn; + protected final CallableStatement callableStatement; public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { this.options = options; this.conn = conn; + callableStatement = conn.prepareCall(getSql()); + createStatement(); } @@ -34,8 +39,6 @@ protected int createStatement() throws SQLException { OracleConnection oraConn = conn.unwrap(OracleConnection.class); - callableStatement = conn.prepareCall(getSql()); - int paramIdx = 0; callableStatement.setArray( @@ -90,6 +93,7 @@ public void execute() throws SQLException { callableStatement.execute(); } + @Override public void close() throws SQLException { if (callableStatement != null) callableStatement.close(); diff --git a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java index ab3fa6a..9a0bb48 100644 --- a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java @@ -2,13 +2,15 @@ import java.sql.SQLException; -/** Interface to hide the concrete Statement-implementations of TestRunner +/** + * Interface to hide the concrete Statement-implementations of TestRunner * * @author pesse */ -public interface TestRunnerStatement { +public interface TestRunnerStatement extends AutoCloseable { void execute() throws SQLException; + @Override void close() throws SQLException; } diff --git a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java index a60ea84..abe844c 100644 --- a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java +++ b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java @@ -1,9 +1,7 @@ package org.utplsql.api.testRunner; -import org.utplsql.api.DBHelper; import org.utplsql.api.TestRunnerOptions; import org.utplsql.api.Version; -import org.utplsql.api.compatibility.OptionalFeatures; import org.utplsql.api.exception.InvalidVersionException; import java.sql.Connection; @@ -32,11 +30,14 @@ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version datab else if (databaseVersion.isLessThan(new Version("3.1.2"))) stmt = new Pre312TestRunnerStatement(options, conn); - } catch ( InvalidVersionException e ) {} + } catch ( InvalidVersionException ignored ) {} if ( stmt == null ) stmt = new ActualTestRunnerStatement(options, conn); return stmt; } + + private TestRunnerStatementProvider() { + } } diff --git a/src/test/java/org/utplsql/api/RegisterCustomReporterTest.java b/src/test/java/org/utplsql/api/RegisterCustomReporterTest.java index 6073163..799b0fb 100644 --- a/src/test/java/org/utplsql/api/RegisterCustomReporterTest.java +++ b/src/test/java/org/utplsql/api/RegisterCustomReporterTest.java @@ -1,7 +1,6 @@ package org.utplsql.api; import org.junit.jupiter.api.Test; -import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.reporter.DefaultReporter; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; diff --git a/src/test/java/org/utplsql/api/ReporterInspectorIT.java b/src/test/java/org/utplsql/api/ReporterInspectorIT.java index 7cb4b3d..c06dc52 100644 --- a/src/test/java/org/utplsql/api/ReporterInspectorIT.java +++ b/src/test/java/org/utplsql/api/ReporterInspectorIT.java @@ -1,25 +1,18 @@ package org.utplsql.api; -import oracle.jdbc.OracleCallableStatement; -import oracle.jdbc.OracleConnection; -import oracle.jdbc.OracleType; import org.junit.jupiter.api.Test; import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.exception.InvalidVersionException; import org.utplsql.api.reporter.CoreReporters; -import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.api.reporter.inspect.ReporterInfo; import org.utplsql.api.reporter.inspect.ReporterInspector; -import java.sql.PreparedStatement; import java.sql.SQLException; -import java.sql.SQLType; import java.util.Comparator; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; public class ReporterInspectorIT extends AbstractDatabaseTest { diff --git a/src/test/java/org/utplsql/api/TestRunnerIT.java b/src/test/java/org/utplsql/api/TestRunnerIT.java index 48ddaaa..0e3452c 100644 --- a/src/test/java/org/utplsql/api/TestRunnerIT.java +++ b/src/test/java/org/utplsql/api/TestRunnerIT.java @@ -5,7 +5,7 @@ import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.exception.InvalidVersionException; import org.utplsql.api.exception.SomeTestsFailedException; -import org.utplsql.api.reporter.*; +import org.utplsql.api.reporter.CoreReporters; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/test/java/org/utplsql/api/VersionObjectTest.java b/src/test/java/org/utplsql/api/VersionObjectTest.java index e7619d0..04cacc2 100644 --- a/src/test/java/org/utplsql/api/VersionObjectTest.java +++ b/src/test/java/org/utplsql/api/VersionObjectTest.java @@ -3,9 +3,7 @@ import org.junit.jupiter.api.Test; import org.utplsql.api.exception.InvalidVersionException; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; public class VersionObjectTest { diff --git a/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java b/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java index 125ffd4..55a3793 100644 --- a/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java +++ b/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java @@ -3,13 +3,13 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - import java.io.File; import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class CoverageHTMLReporterAssetTest { private static final String TEST_FOLDER = "__testAssets"; diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index 9364b20..7c2a1bb 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -8,7 +8,6 @@ import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; public class TestRunnerStatementProviderIT extends AbstractDatabaseTest {