From ff4972c0799328966b52e7c188fe3124de57278b Mon Sep 17 00:00:00 2001 From: Pazus Date: Fri, 22 Feb 2019 22:19:26 +0300 Subject: [PATCH 1/2] reformat and cleanup all java code with defined codestyle --- .idea/codeStyles/Project.xml | 10 ++ .idea/codeStyles/codeStyleConfig.xml | 5 + .../java/org/utplsql/api/CustomTypes.java | 3 +- src/main/java/org/utplsql/api/DBHelper.java | 16 ++- .../utplsql/api/EnvironmentVariableUtil.java | 3 +- src/main/java/org/utplsql/api/FileMapper.java | 7 +- .../java/org/utplsql/api/FileMapping.java | 3 +- .../org/utplsql/api/JavaApiVersionInfo.java | 25 ++-- .../java/org/utplsql/api/ResourceUtil.java | 6 +- src/main/java/org/utplsql/api/TestRunner.java | 49 ++++---- .../org/utplsql/api/TestRunnerOptions.java | 5 +- src/main/java/org/utplsql/api/Version.java | 111 +++++++++-------- .../api/compatibility/CompatibilityProxy.java | 88 +++++++------- .../api/compatibility/OptionalFeatures.java | 7 +- .../utplsql/api/db/DatabaseInformation.java | 9 +- .../api/db/DefaultDatabaseInformation.java | 26 ++-- .../DatabaseNotCompatibleException.java | 26 ++-- .../exception/InvalidVersionException.java | 10 +- .../exception/SomeTestsFailedException.java | 2 +- .../UtPLSQLNotInstalledException.java | 5 +- .../outputBuffer/AbstractOutputBuffer.java | 25 ++-- .../CompatibilityOutputBufferPre310.java | 5 +- .../api/outputBuffer/DefaultOutputBuffer.java | 1 + .../api/outputBuffer/NonOutputBuffer.java | 8 +- .../api/outputBuffer/OutputBuffer.java | 15 ++- .../outputBuffer/OutputBufferProvider.java | 64 +++++----- .../utplsql/api/reporter/CoreReporters.java | 15 ++- .../api/reporter/CoverageHTMLReporter.java | 112 ++++++++--------- .../utplsql/api/reporter/DefaultReporter.java | 7 +- ...faultReporterFactoryMethodRegistrator.java | 5 +- .../api/reporter/DocumentationReporter.java | 24 ++-- .../org/utplsql/api/reporter/Reporter.java | 55 ++++----- .../utplsql/api/reporter/ReporterFactory.java | 113 ++++++++++-------- .../inspect/AbstractReporterInspector.java | 4 +- .../api/reporter/inspect/ReporterInfo.java | 13 +- .../reporter/inspect/ReporterInspector.java | 17 +-- .../inspect/ReporterInspector310.java | 18 +-- .../AbstractTestRunnerStatement.java | 5 +- .../testRunner/ActualTestRunnerStatement.java | 9 +- .../testRunner/Pre303TestRunnerStatement.java | 3 +- .../testRunner/Pre312TestRunnerStatement.java | 9 +- .../TestRunnerStatementProvider.java | 31 +++-- .../org/utplsql/api/AbstractDatabaseTest.java | 19 +-- .../api/EnvironmentVariableUtilTest.java | 7 +- .../java/org/utplsql/api/FileMapperIT.java | 3 +- .../org/utplsql/api/OptionalFeaturesIT.java | 15 ++- .../java/org/utplsql/api/OutputBufferIT.java | 8 +- .../org/utplsql/api/ReporterInspectorIT.java | 18 +-- .../java/org/utplsql/api/TestRunnerIT.java | 6 +- .../org/utplsql/api/VersionObjectTest.java | 38 +++--- .../CoverageHTMLReporterAssetTest.java | 42 +++---- 51 files changed, 620 insertions(+), 510 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..4f717ff --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main/java/org/utplsql/api/CustomTypes.java b/src/main/java/org/utplsql/api/CustomTypes.java index 2d770ce..1c04c23 100644 --- a/src/main/java/org/utplsql/api/CustomTypes.java +++ b/src/main/java/org/utplsql/api/CustomTypes.java @@ -17,6 +17,7 @@ public final class CustomTypes { public static final String UT_KEY_VALUE_PAIR = "UT_KEY_VALUE_PAIR"; public static final String UT_KEY_VALUE_PAIRS = "UT_KEY_VALUE_PAIRS"; - private CustomTypes() {} + private CustomTypes() { + } } diff --git a/src/main/java/org/utplsql/api/DBHelper.java b/src/main/java/org/utplsql/api/DBHelper.java index c9dfa52..09c109c 100644 --- a/src/main/java/org/utplsql/api/DBHelper.java +++ b/src/main/java/org/utplsql/api/DBHelper.java @@ -14,10 +14,12 @@ */ public final class DBHelper { - private DBHelper() {} + private DBHelper() { + } /** * Return a new sys_guid from database. + * * @param conn the connection * @return the new id string * @throws SQLException any database error @@ -47,7 +49,8 @@ public static String getCurrentSchema(Connection conn) throws SQLException { } } - /** Returns the Frameworks version string of the given connection + /** + * Returns the Frameworks version string of the given connection * Deprecated. Use DatabaseInformation-Interface instead. * * @param conn Active db connection @@ -55,13 +58,14 @@ public static String getCurrentSchema(Connection conn) throws SQLException { * @throws SQLException any database error */ @Deprecated - public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException { + public static Version getDatabaseFrameworkVersion(Connection conn) throws SQLException { DatabaseInformation databaseInformation = new DefaultDatabaseInformation(); return databaseInformation.getUtPlsqlFrameworkVersion(conn); } - /** Returns the Oracle database Version from a given connection object + /** + * Returns the Oracle database Version from a given connection object * Deprecated. Use DatabaseInformation-Interface instead. * * @param conn Connection-Object @@ -69,13 +73,14 @@ public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLE * @throws SQLException any database error */ @Deprecated - public static String getOracleDatabaseVersion( Connection conn ) throws SQLException { + public static String getOracleDatabaseVersion(Connection conn) throws SQLException { DatabaseInformation databaseInformation = new DefaultDatabaseInformation(); return databaseInformation.getOracleVersion(conn); } /** * Enable the dbms_output buffer with unlimited size. + * * @param conn the connection */ public static void enableDBMSOutput(Connection conn) { @@ -88,6 +93,7 @@ public static void enableDBMSOutput(Connection conn) { /** * Disable the dbms_output buffer. + * * @param conn the connection */ public static void disableDBMSOutput(Connection conn) { diff --git a/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java b/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java index 9552fee..90ca49f 100644 --- a/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java +++ b/src/main/java/org/utplsql/api/EnvironmentVariableUtil.java @@ -20,7 +20,8 @@ */ public class EnvironmentVariableUtil { - private EnvironmentVariableUtil() {} + private EnvironmentVariableUtil() { + } /** * Returns the value for a given key from environment (see class description) diff --git a/src/main/java/org/utplsql/api/FileMapper.java b/src/main/java/org/utplsql/api/FileMapper.java index 8fae53f..150dca3 100644 --- a/src/main/java/org/utplsql/api/FileMapper.java +++ b/src/main/java/org/utplsql/api/FileMapper.java @@ -11,7 +11,8 @@ public final class FileMapper { - private FileMapper() {} + private FileMapper() { + } /** * Call the database api to build the custom file mappings. @@ -27,7 +28,7 @@ public static Array buildFileMappingArray( CallableStatement callableStatement = conn.prepareCall( "BEGIN " + - "? := ut_file_mapper.build_file_mappings(" + + "? := ut_file_mapper.build_file_mappings(" + "a_object_owner => ?, " + "a_file_paths => ?, " + "a_file_to_object_type_mapping => ?, " + @@ -35,7 +36,7 @@ public static Array buildFileMappingArray( "a_object_owner_subexpression => ?, " + "a_object_name_subexpression => ?, " + "a_object_type_subexpression => ?); " + - "END;"); + "END;"); int paramIdx = 0; callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS); diff --git a/src/main/java/org/utplsql/api/FileMapping.java b/src/main/java/org/utplsql/api/FileMapping.java index e7fea84..be86e2a 100644 --- a/src/main/java/org/utplsql/api/FileMapping.java +++ b/src/main/java/org/utplsql/api/FileMapping.java @@ -15,7 +15,8 @@ public class FileMapping implements SQLData { private String objectName; private String objectType; - public FileMapping() {} + public FileMapping() { + } public FileMapping(String fileName, String objectOwner, String objectName, String objectType) { this.fileName = fileName; diff --git a/src/main/java/org/utplsql/api/JavaApiVersionInfo.java b/src/main/java/org/utplsql/api/JavaApiVersionInfo.java index 03171e4..503b84d 100644 --- a/src/main/java/org/utplsql/api/JavaApiVersionInfo.java +++ b/src/main/java/org/utplsql/api/JavaApiVersionInfo.java @@ -5,33 +5,38 @@ import java.io.InputStream; import java.io.InputStreamReader; -/** This class is getting updated automatically by the build process. +/** + * This class is getting updated automatically by the build process. * Please do not update its constants manually cause they will be overwritten. * * @author pesse */ public class JavaApiVersionInfo { - private JavaApiVersionInfo() { } - - private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api"; private static String MAVEN_PROJECT_VERSION = "unknown"; static { try { - try ( InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-api.version"); - BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { + try (InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-api.version"); + BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { MAVEN_PROJECT_VERSION = reader.readLine(); } - } - catch ( IOException e ) { + } catch (IOException e) { System.out.println("WARNING: Could not get Version information!"); } } - public static String getVersion() { return MAVEN_PROJECT_VERSION; } - public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); } + private JavaApiVersionInfo() { + } + + public static String getVersion() { + return MAVEN_PROJECT_VERSION; + } + + public static String getInfo() { + return MAVEN_PROJECT_NAME + " " + getVersion(); + } } diff --git a/src/main/java/org/utplsql/api/ResourceUtil.java b/src/main/java/org/utplsql/api/ResourceUtil.java index e8bbbc4..9f6c225 100644 --- a/src/main/java/org/utplsql/api/ResourceUtil.java +++ b/src/main/java/org/utplsql/api/ResourceUtil.java @@ -21,7 +21,8 @@ */ public class ResourceUtil { - private 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 @@ -68,8 +69,9 @@ public static List getListOfChildren(Path resourceAsPath, boolean filesOnl // Get entry-path with root element so we can compare it Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString())); - if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory())) + if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory())) { result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount())); + } } } resourcePath.getFileSystem().close(); diff --git a/src/main/java/org/utplsql/api/TestRunner.java b/src/main/java/org/utplsql/api/TestRunner.java index b56b772..d738754 100644 --- a/src/main/java/org/utplsql/api/TestRunner.java +++ b/src/main/java/org/utplsql/api/TestRunner.java @@ -28,9 +28,9 @@ public class TestRunner { private static final Logger logger = LoggerFactory.getLogger(TestRunner.class); private final TestRunnerOptions options = new TestRunnerOptions(); + private final List reporterNames = new ArrayList<>(); private CompatibilityProxy compatibilityProxy; private ReporterFactory reporterFactory; - private final List reporterNames = new ArrayList<>(); public TestRunner addPath(String path) { options.pathList.add(path); @@ -47,11 +47,12 @@ public TestRunner addReporter(Reporter reporter) { return this; } - public TestRunner addReporter( String reporterName ) { - if ( reporterFactory != null ) + public TestRunner addReporter(String reporterName) { + if (reporterFactory != null) { options.reporterList.add(reporterFactory.createReporter(reporterName)); - else + } else { reporterNames.add(reporterName); + } return this; } @@ -105,22 +106,22 @@ public TestRunner failOnErrors(boolean failOnErrors) { return this; } - public TestRunner skipCompatibilityCheck( boolean skipCompatibilityCheck ) - { + public TestRunner skipCompatibilityCheck(boolean skipCompatibilityCheck) { options.skipCompatibilityCheck = skipCompatibilityCheck; return this; } - public TestRunner setReporterFactory( ReporterFactory reporterFactory ) { + public TestRunner setReporterFactory(ReporterFactory reporterFactory) { this.reporterFactory = reporterFactory; return this; } private void delayedAddReporters() { - if ( reporterFactory != null ) - reporterNames.forEach( this::addReporter ); - else + if (reporterFactory != null) { + reporterNames.forEach(this::addReporter); + } else { throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!"); + } } public void run(Connection conn) throws SQLException { @@ -132,8 +133,9 @@ public void run(Connection conn) throws SQLException { compatibilityProxy = new CompatibilityProxy(conn, options.skipCompatibilityCheck, databaseInformation); logger.info("Running on utPLSQL {}", compatibilityProxy.getDatabaseVersion()); - if ( reporterFactory == null ) + if (reporterFactory == null) { reporterFactory = ReporterFactory.createDefault(compatibilityProxy); + } delayedAddReporters(); @@ -141,8 +143,9 @@ public void run(Connection conn) throws SQLException { compatibilityProxy.failOnNotCompatible(); logger.info("Initializing reporters"); - for (Reporter r : options.reporterList) + for (Reporter r : options.reporterList) { validateReporter(conn, r); + } if (options.pathList.isEmpty()) { options.pathList.add(databaseInformation.getCurrentSchema(conn)); @@ -153,18 +156,16 @@ public void run(Connection conn) throws SQLException { options.reporterList.add(new DocumentationReporter().init(conn)); } - try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) { + try (TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) { logger.info("Running tests"); testRunnerStatement.execute(); logger.info("Running tests finished."); } catch (SQLException e) { if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) { throw new SomeTestsFailedException(e.getMessage(), e); - } - else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { + } else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { throw new UtPLSQLNotInstalledException(e); - } - else { + } else { throw e; } } @@ -172,24 +173,28 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { /** * Check if the reporter was initialized, if not call reporter.init. - * @param conn the database connection + * + * @param conn the database connection * @param reporter the reporter * @throws SQLException any sql exception */ private void validateReporter(Connection conn, Reporter reporter) throws SQLException { - if (!reporter.isInit() || reporter.getId() == null || reporter.getId().isEmpty()) + if (!reporter.isInit() || reporter.getId() == null || reporter.getId().isEmpty()) { reporter.init(conn, compatibilityProxy, reporterFactory); + } } - /** Returns the databaseVersion the TestRunner was run against + /** + * Returns the databaseVersion the TestRunner was run against * * @return Version of the database the TestRunner was run against */ public Version getUsedDatabaseVersion() { - if ( compatibilityProxy != null ) + if (compatibilityProxy != null) { return compatibilityProxy.getDatabaseVersion(); - else + } else { return null; + } } } diff --git a/src/main/java/org/utplsql/api/TestRunnerOptions.java b/src/main/java/org/utplsql/api/TestRunnerOptions.java index 936254f..059d9ba 100644 --- a/src/main/java/org/utplsql/api/TestRunnerOptions.java +++ b/src/main/java/org/utplsql/api/TestRunnerOptions.java @@ -6,19 +6,20 @@ import java.util.ArrayList; import java.util.List; -/** Holds the various possible options of TestRunner +/** + * Holds the various possible options of TestRunner * * @author pesse */ public class TestRunnerOptions { public final List pathList = new ArrayList<>(); public final List reporterList = new ArrayList<>(); - public boolean colorConsole = false; 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 boolean colorConsole = false; 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 f7f1cf4..cc2ef3e 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -12,20 +12,21 @@ import static java.util.stream.Collectors.toMap; -/** Simple class to parse utPLSQL Version-information and provide the separate version-numbers +/** + * Simple class to parse utPLSQL Version-information and provide the separate version-numbers * * @author pesse */ public class Version implements Comparable { - public final static Version V3_0_0 = new Version("3.0.0", 3,0,0,null, true); - public final static Version V3_0_1 = new Version("3.0.1", 3,0,1,null, true); - public final static Version V3_0_2 = new Version("3.0.2", 3,0,2,null, true); - public final static Version V3_0_3 = new Version("3.0.3", 3,0,3,null, true); - public final static Version V3_0_4 = new Version("3.0.4", 3,0,4,null, true); - public final static Version V3_1_0 = new Version("3.1.0", 3,1,0,null, true); - public final static Version V3_1_1 = new Version("3.1.1", 3,1,1,null, true); - public final static Version V3_1_2 = new Version("3.1.2", 3,1,2,null, true); + public final static Version V3_0_0 = new Version("3.0.0", 3, 0, 0, null, true); + public final static Version V3_0_1 = new Version("3.0.1", 3, 0, 1, null, true); + public final static Version V3_0_2 = new Version("3.0.2", 3, 0, 2, null, true); + public final static Version V3_0_3 = new Version("3.0.3", 3, 0, 3, null, true); + public final static Version V3_0_4 = new Version("3.0.4", 3, 0, 4, null, true); + public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, null, true); + public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, null, true); + public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, null, true); private final static Map knownVersions = Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2) .collect(toMap(Version::toString, Function.identity())); @@ -57,7 +58,7 @@ public Version(String versionString) { this.origString = dummy.origString; this.major = dummy.major; - this.minor =dummy.minor; + this.minor = dummy.minor; this.bugfix = dummy.bugfix; this.build = dummy.build; this.valid = dummy.valid; @@ -69,8 +70,7 @@ public static Version create(final String versionString) { return version != null ? version : parseVersionString(origString); } - private static Version parseVersionString(String origString) - { + private static Version parseVersionString(String origString) { Integer major = null; Integer minor = null; @@ -83,21 +83,23 @@ private static Version parseVersionString(String origString) 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)); + } - // We need a valid major version as minimum requirement for a Version object to be valid + // We need a valid major version as minimum requirement for a Version object to be valid valid = major != null; } - } - catch ( NumberFormatException e ) - { + } catch (NumberFormatException e) { valid = false; } @@ -133,80 +135,92 @@ public boolean isValid() { return valid; } - /** Returns a normalized form of the parsed version information + /** + * Returns a normalized form of the parsed version information * * @return */ - public String getNormalizedString() - { - if ( isValid() ) { + public String getNormalizedString() { + if (isValid()) { StringBuilder sb = new StringBuilder(); sb.append(major); - if ( minor != null ) + if (minor != null) { sb.append(".").append(minor); - if ( bugfix != null ) + } + if (bugfix != null) { sb.append(".").append(bugfix); - if ( build != null ) + } + if (build != null) { sb.append(".").append(build); + } return sb.toString(); - } - else + } else { return "invalid"; + } } - private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2 ) { - if ( i1 == null && i2 == null ) + private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) { + if (i1 == null && i2 == null) { return 0; - else if ( i1 == null ) + } else if (i1 == null) { return -1; - else if ( i2 == null ) + } else if (i2 == null) { return 1; - else return i1.compareTo(i2); + } else { + return i1.compareTo(i2); + } } @Override public int compareTo(Version o) { int curResult; - if ( isValid() && o.isValid() ) { + if (isValid() && o.isValid()) { curResult = compareToWithNulls(getMajor(), o.getMajor()); - if ( curResult != 0 ) + if (curResult != 0) { return curResult; + } curResult = compareToWithNulls(getMinor(), o.getMinor()); - if ( curResult != 0 ) + if (curResult != 0) { return curResult; + } curResult = compareToWithNulls(getBugfix(), o.getBugfix()); - if ( curResult != 0 ) + if (curResult != 0) { return curResult; + } curResult = compareToWithNulls(getBuild(), o.getBuild()); - if ( curResult != 0 ) + if (curResult != 0) { return curResult; + } } return 0; } - private void versionsAreValid( Version v ) throws InvalidVersionException { - if ( !isValid() ) + private void versionsAreValid(Version v) throws InvalidVersionException { + if (!isValid()) { throw new InvalidVersionException(this); + } - if ( !v.isValid() ) + if (!v.isValid()) { throw new InvalidVersionException(v); + } } - /** Compares this version to a given version and returns true if this version is greater or equal than the given one + /** + * Compares this version to a given version and returns true if this version is greater or equal than the given one * Throws an InvalidVersionException if either this or the given version are invalid * * @param v Version to compare with * @return * @throws InvalidVersionException */ - public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException { + public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException { versionsAreValid(v); @@ -214,23 +228,20 @@ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException } - public boolean isGreaterThan( Version v) throws InvalidVersionException - { + public boolean isGreaterThan(Version v) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) > 0; } - public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException - { + public boolean isLessOrEqualThan(Version v) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) <= 0; } - public boolean isLessThan( Version v) throws InvalidVersionException - { + public boolean isLessThan(Version v) throws InvalidVersionException { versionsAreValid(v); 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 068bd31..0c184a0 100644 --- a/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java +++ b/src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java @@ -15,7 +15,8 @@ import java.sql.SQLException; import java.util.Objects; -/** Class to check compatibility with database framework and also to give several specific implementations depending +/** + * Class to check compatibility with database framework and also to give several specific implementations depending * on the version of the connected framework. * If one skips the compatibility check, the Proxy acts as like the framework has the same version as the API * @@ -23,52 +24,54 @@ */ public class CompatibilityProxy { - private static final String UTPLSQL_API_VERSION = "3.1.1"; public static final String UTPLSQL_COMPATIBILITY_VERSION = "3"; - + private static final String UTPLSQL_API_VERSION = "3.1.1"; + private final DatabaseInformation databaseInformation; private Version databaseVersion; private boolean compatible = false; - private final DatabaseInformation databaseInformation; - public CompatibilityProxy( Connection conn ) throws SQLException { + public CompatibilityProxy(Connection conn) throws SQLException { this(conn, false, null); } - public CompatibilityProxy( Connection conn, DatabaseInformation databaseInformation ) throws SQLException { + public CompatibilityProxy(Connection conn, DatabaseInformation databaseInformation) throws SQLException { this(conn, false, databaseInformation); } - public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck ) throws SQLException { + public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck) throws SQLException { this(conn, skipCompatibilityCheck, null); } - public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck, DatabaseInformation databaseInformation ) throws SQLException { - this.databaseInformation = (databaseInformation != null ) - ? databaseInformation - : new DefaultDatabaseInformation(); + public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, DatabaseInformation databaseInformation) throws SQLException { + this.databaseInformation = (databaseInformation != null) + ? databaseInformation + : new DefaultDatabaseInformation(); - if ( skipCompatibilityCheck ) + if (skipCompatibilityCheck) { doExpectCompatibility(); - else + } else { doCompatibilityCheckWithDatabase(conn); + } } - /** Receives the current framework version from database and checks - depending on the framework version - whether + /** + * Receives the current framework version from database and checks - depending on the framework version - whether * the API version is compatible or not. * * @param conn * @throws SQLException */ - private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException - { + private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLException { databaseVersion = databaseInformation.getUtPlsqlFrameworkVersion(conn); Version clientVersion = Version.create(UTPLSQL_COMPATIBILITY_VERSION); - if ( databaseVersion == null ) + if (databaseVersion == null) { throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null); + } - if ( databaseVersion.getMajor() == null ) + if (databaseVersion.getMajor() == null) { throw new DatabaseNotCompatibleException("Illegal database version: " + databaseVersion.toString(), clientVersion, databaseVersion, null); + } if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) { try { @@ -76,21 +79,22 @@ private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLExcep } catch (SQLException e) { throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), clientVersion, Version.create("Unknown"), e); } - } else + } else { compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION); + } } - /** Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API - * + /** + * Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API */ - private void doExpectCompatibility() - { + private void doExpectCompatibility() { databaseVersion = Version.create(UTPLSQL_API_VERSION); compatible = true; } /** * Check the utPLSQL version compatibility. + * * @param conn the connection * @return true if the requested utPLSQL version is compatible with the one installed on database * @throws SQLException any database error @@ -100,20 +104,21 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str try { return databaseInformation.frameworkCompatibilityCheck(conn, requested, current) == 1; } catch (SQLException e) { - if (e.getErrorCode() == 6550) + if (e.getErrorCode() == 6550) { return false; - else + } else { throw e; + } } } - /** Simple fallback check for compatiblity: Major and Minor version must be equal + /** + * Simple fallback check for compatiblity: Major and Minor version must be equal * * @param requested * @return */ - private boolean versionCompatibilityCheckPre303(String requested ) - { + private boolean versionCompatibilityCheckPre303(String requested) { Version requestedVersion = Version.create(requested); Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString()); @@ -122,39 +127,38 @@ private boolean versionCompatibilityCheckPre303(String requested ) || requestedVersion.getMinor().equals(databaseVersion.getMinor())); } - /** Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not + /** + * Checks if actual API-version is compatible with utPLSQL database version and throws a DatabaseNotCompatibleException if not * Throws a DatabaseNotCompatibleException if version compatibility can not be checked. - * */ - public void failOnNotCompatible() throws DatabaseNotCompatibleException - { - if ( !isCompatible() ) - throw new DatabaseNotCompatibleException( databaseVersion ); + public void failOnNotCompatible() throws DatabaseNotCompatibleException { + if (!isCompatible()) { + throw new DatabaseNotCompatibleException(databaseVersion); + } } - public boolean isCompatible() - { + public boolean isCompatible() { return compatible; } - public Version getDatabaseVersion() - { + public Version getDatabaseVersion() { return databaseVersion; } - /** Returns a TestRunnerStatement compatible with the current framework + /** + * Returns a TestRunnerStatement compatible with the current framework * * @param options * @param conn * @return * @throws SQLException */ - public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException - { + public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(databaseVersion, options, conn); } - /** Returns an OutputBuffer compatible with the current framework + /** + * Returns an OutputBuffer compatible with the current framework * * @param reporter * @param conn diff --git a/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java b/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java index b2fed20..629ec5b 100644 --- a/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java +++ b/src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java @@ -15,18 +15,17 @@ public enum OptionalFeatures { private final Version minVersion; private final Version maxVersion; - OptionalFeatures( String minVersion, String maxVersion ) - { + OptionalFeatures(String minVersion, String maxVersion) { this.minVersion = minVersion != null ? Version.create(minVersion) : null; this.maxVersion = maxVersion != null ? Version.create(maxVersion) : null; } - public boolean isAvailableFor(Version version ) { + public boolean isAvailableFor(Version version) { try { return (minVersion == null || version.isGreaterOrEqualThan(minVersion)) && (maxVersion == null || maxVersion.isGreaterOrEqualThan(version)); - } catch ( InvalidVersionException e ) { + } catch (InvalidVersionException e) { return false; // We have no optional features for invalid versions } } diff --git a/src/main/java/org/utplsql/api/db/DatabaseInformation.java b/src/main/java/org/utplsql/api/db/DatabaseInformation.java index 8ea058f..6e76cfa 100644 --- a/src/main/java/org/utplsql/api/db/DatabaseInformation.java +++ b/src/main/java/org/utplsql/api/db/DatabaseInformation.java @@ -6,17 +6,18 @@ import java.sql.Connection; import java.sql.SQLException; -/** Abstraction-interface to encapsulate Database-Calls (and potentially mock them) +/** + * Abstraction-interface to encapsulate Database-Calls (and potentially mock them) * * @author pesse */ public interface DatabaseInformation { - Version getUtPlsqlFrameworkVersion(Connection conn ) throws SQLException; + Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException; - String getOracleVersion( Connection conn ) throws SQLException; + String getOracleVersion(Connection conn) throws SQLException; - String getCurrentSchema( Connection conn ) throws SQLException; + String getCurrentSchema(Connection conn) throws SQLException; int frameworkCompatibilityCheck(Connection conn, String requested, @Nullable String current) throws SQLException; } diff --git a/src/main/java/org/utplsql/api/db/DefaultDatabaseInformation.java b/src/main/java/org/utplsql/api/db/DefaultDatabaseInformation.java index 4fabee7..181ffa6 100644 --- a/src/main/java/org/utplsql/api/db/DefaultDatabaseInformation.java +++ b/src/main/java/org/utplsql/api/db/DefaultDatabaseInformation.java @@ -11,19 +11,20 @@ public class DefaultDatabaseInformation implements DatabaseInformation { @Override public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException { Version result = Version.create(""); - try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual")) - { + try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual")) { ResultSet rs = stmt.executeQuery(); - if ( rs.next() ) + if (rs.next()) { result = Version.create(rs.getString(1)); + } rs.close(); - } catch ( SQLException e ) { - if ( e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE ) + } catch (SQLException e) { + if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) { throw new UtPLSQLNotInstalledException(e); - else + } else { throw e; + } } return result; @@ -32,12 +33,12 @@ public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException { @Override public String getOracleVersion(Connection conn) throws SQLException { String result = null; - try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) - { + try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) { ResultSet rs = stmt.executeQuery(); - if ( rs.next() ) + if (rs.next()) { result = rs.getString(1); + } } return result; @@ -54,14 +55,15 @@ public String getCurrentSchema(Connection conn) throws SQLException { @Override public int frameworkCompatibilityCheck(Connection conn, String requested, @Nullable String current) throws SQLException { - try(CallableStatement 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); - if (current == null) + if (current == null) { callableStatement.setNull(3, Types.VARCHAR); - else + } else { callableStatement.setString(3, current); + } callableStatement.executeUpdate(); return callableStatement.getInt(1); diff --git a/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java b/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java index a63e784..b7b7111 100644 --- a/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java +++ b/src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java @@ -5,50 +5,44 @@ import java.sql.SQLException; -/** Custom exception to indicate API is not compatible with database framework +/** + * Custom exception to indicate API is not compatible with database framework * * @author pesse - * */ public class DatabaseNotCompatibleException extends SQLException { private final Version clientVersion; private final Version databaseVersion; - public DatabaseNotCompatibleException( String message, Version clientVersion, Version databaseVersion, Throwable cause ) - { + public DatabaseNotCompatibleException(String message, Version clientVersion, Version databaseVersion, Throwable cause) { super(message, cause); this.clientVersion = clientVersion; this.databaseVersion = databaseVersion; } - public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion, Throwable cause ) - { + public DatabaseNotCompatibleException(Version clientVersion, Version databaseVersion, Throwable cause) { this("utPLSQL API (" + clientVersion + ") not compatible with database (" + databaseVersion + ")", clientVersion, databaseVersion, cause); } - public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion ) - { + public DatabaseNotCompatibleException(Version clientVersion, Version databaseVersion) { this(clientVersion, databaseVersion, null); } - public DatabaseNotCompatibleException( Version databaseVersion, Throwable cause ) - { - this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause ); + public DatabaseNotCompatibleException(Version databaseVersion, Throwable cause) { + this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause); } - public DatabaseNotCompatibleException( Version databaseVersion ) - { - this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null ); + public DatabaseNotCompatibleException(Version databaseVersion) { + this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null); } public Version getClientVersion() { return clientVersion; } - public Version getDatabaseVersion() - { + public Version getDatabaseVersion() { return databaseVersion; } } diff --git a/src/main/java/org/utplsql/api/exception/InvalidVersionException.java b/src/main/java/org/utplsql/api/exception/InvalidVersionException.java index 49942ae..3350e7d 100644 --- a/src/main/java/org/utplsql/api/exception/InvalidVersionException.java +++ b/src/main/java/org/utplsql/api/exception/InvalidVersionException.java @@ -2,19 +2,19 @@ import org.utplsql.api.Version; -/** Exception thrown when trying to do stuff which requires a valid version object (like comparing) +/** + * Exception thrown when trying to do stuff which requires a valid version object (like comparing) * * @author pesse */ public class InvalidVersionException extends Exception { private final Version version; - public InvalidVersionException( Version version ) { - this( version, null ); + public InvalidVersionException(Version version) { + this(version, null); } - public InvalidVersionException( Version version, Throwable cause ) - { + public InvalidVersionException(Version version, Throwable cause) { super("Version '" + version.toString() + "' is invalid", cause); this.version = version; diff --git a/src/main/java/org/utplsql/api/exception/SomeTestsFailedException.java b/src/main/java/org/utplsql/api/exception/SomeTestsFailedException.java index 3fc2379..a7f8ffe 100644 --- a/src/main/java/org/utplsql/api/exception/SomeTestsFailedException.java +++ b/src/main/java/org/utplsql/api/exception/SomeTestsFailedException.java @@ -10,7 +10,7 @@ public class SomeTestsFailedException extends SQLException { public static final int ERROR_CODE = 20213; - public SomeTestsFailedException(String reason, @Nullable Throwable cause) { + public SomeTestsFailedException(String reason, @Nullable Throwable cause) { super(reason, cause); } diff --git a/src/main/java/org/utplsql/api/exception/UtPLSQLNotInstalledException.java b/src/main/java/org/utplsql/api/exception/UtPLSQLNotInstalledException.java index 0e218a3..fa197ef 100644 --- a/src/main/java/org/utplsql/api/exception/UtPLSQLNotInstalledException.java +++ b/src/main/java/org/utplsql/api/exception/UtPLSQLNotInstalledException.java @@ -2,7 +2,8 @@ import java.sql.SQLException; -/** Exception to track when utPLSQL framework is not installed or accessible on the used database +/** + * Exception to track when utPLSQL framework is not installed or accessible on the used database * * @author pesse */ @@ -10,7 +11,7 @@ public class UtPLSQLNotInstalledException extends SQLException { public static final int ERROR_CODE = 904; - public UtPLSQLNotInstalledException( SQLException cause ) { + public UtPLSQLNotInstalledException(SQLException cause) { super("utPLSQL framework is not installed on your database or not accessable to the user you are connected with", cause); } } diff --git a/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java index 53d4182..5354db6 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java @@ -24,6 +24,7 @@ abstract class AbstractOutputBuffer implements OutputBuffer { /** * Creates a new DefaultOutputBuffer. + * * @param reporter the reporter to be used */ AbstractOutputBuffer(Reporter reporter) { @@ -35,6 +36,7 @@ abstract class AbstractOutputBuffer implements OutputBuffer { /** * Returns the reporter used by this buffer. + * * @return the reporter instance */ public Reporter getReporter() { @@ -49,8 +51,9 @@ public OutputBuffer setFetchSize(int fetchSize) { /** * Print the lines as soon as they are produced and write to a PrintStream. + * * @param conn DB connection - * @param ps the PrintStream to be used, e.g: System.out + * @param ps the PrintStream to be used, e.g: System.out * @throws SQLException any sql errors */ public void printAvailable(Connection conn, PrintStream ps) throws SQLException { @@ -61,22 +64,25 @@ public void printAvailable(Connection conn, PrintStream ps) throws SQLException /** * Print the lines as soon as they are produced and write to a list of PrintStreams. - * @param conn DB connection + * + * @param conn DB connection * @param printStreams the PrintStream list to be used, e.g: System.out, new PrintStream(new FileOutputStream) * @throws SQLException any sql errors */ public void printAvailable(Connection conn, List printStreams) throws SQLException { fetchAvailable(conn, s -> { - for (PrintStream ps : printStreams) + for (PrintStream ps : printStreams) { ps.println(s); + } }); } - protected abstract CallableStatement getLinesCursorStatement( Connection conn ) throws SQLException; + protected abstract CallableStatement getLinesCursorStatement(Connection conn) throws SQLException; /** * Print the lines as soon as they are produced and call the callback passing the new line. - * @param conn DB connection + * + * @param conn DB connection * @param onLineFetched the callback to be called * @throws SQLException any sql errors */ @@ -86,15 +92,17 @@ public void fetchAvailable(Connection conn, Consumer onLineFetched) thro cstmt.execute(); cstmt.setFetchSize(fetchSize); - try ( ResultSet resultSet = (ResultSet) cstmt.getObject(1)) { - while (resultSet.next()) + try (ResultSet resultSet = (ResultSet) cstmt.getObject(1)) { + while (resultSet.next()) { onLineFetched.accept(resultSet.getString("text")); + } } } } /** * Get all lines from output buffer and return it as a list of strings. + * * @param conn DB connection * @return the lines * @throws SQLException any sql errors @@ -106,7 +114,7 @@ public List fetchAll(Connection conn) throws SQLException { cstmt.execute(); cstmt.setFetchSize(fetchSize); - try ( ResultSet resultSet = (ResultSet) cstmt.getObject(1)) { + try (ResultSet resultSet = (ResultSet) cstmt.getObject(1)) { List outputLines = new ArrayList<>(); while (resultSet.next()) { @@ -118,5 +126,4 @@ public List fetchAll(Connection conn) throws SQLException { } - } diff --git a/src/main/java/org/utplsql/api/outputBuffer/CompatibilityOutputBufferPre310.java b/src/main/java/org/utplsql/api/outputBuffer/CompatibilityOutputBufferPre310.java index eb96fa8..423ed03 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/CompatibilityOutputBufferPre310.java +++ b/src/main/java/org/utplsql/api/outputBuffer/CompatibilityOutputBufferPre310.java @@ -7,13 +7,14 @@ import java.sql.Connection; import java.sql.SQLException; -/** Compatibility Output-Buffer for 3.0.0 - 3.0.4 +/** + * Compatibility Output-Buffer for 3.0.0 - 3.0.4 * * @author pesse */ class CompatibilityOutputBufferPre310 extends AbstractOutputBuffer { - CompatibilityOutputBufferPre310( Reporter reporter ) { + CompatibilityOutputBufferPre310(Reporter reporter) { super(reporter); } diff --git a/src/main/java/org/utplsql/api/outputBuffer/DefaultOutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/DefaultOutputBuffer.java index f3d5761..ccf829c 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/DefaultOutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/DefaultOutputBuffer.java @@ -19,6 +19,7 @@ class DefaultOutputBuffer extends AbstractOutputBuffer { /** * Creates a new DefaultOutputBuffer. + * * @param reporter the reporter to be used */ DefaultOutputBuffer(Reporter reporter) { diff --git a/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java index 3e289e2..f354a63 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java @@ -9,7 +9,8 @@ import java.util.List; import java.util.function.Consumer; -/** An OutputBuffer replacement which just returns nothing at all. Suitable for Reporters without any output +/** + * An OutputBuffer replacement which just returns nothing at all. Suitable for Reporters without any output * * @author pesse */ @@ -17,7 +18,7 @@ class NonOutputBuffer implements OutputBuffer { private final Reporter reporter; - NonOutputBuffer( Reporter reporter) { + NonOutputBuffer(Reporter reporter) { this.reporter = reporter; } @@ -41,8 +42,9 @@ public void printAvailable(Connection conn, PrintStream ps) throws SQLException @Override public void printAvailable(Connection conn, List printStreams) throws SQLException { fetchAvailable(conn, s -> { - for (PrintStream ps : printStreams) + for (PrintStream ps : printStreams) { ps.println(s); + } }); } diff --git a/src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java b/src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java index 78ef639..6b2bcbd 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java +++ b/src/main/java/org/utplsql/api/outputBuffer/OutputBuffer.java @@ -12,24 +12,27 @@ public interface OutputBuffer { Reporter getReporter(); - /** Override the fetchSize of the OutputBuffer + /** + * Override the fetchSize of the OutputBuffer * * @param fetchSize the ResultSet fetch-size. * @return this Output-Buffer */ - OutputBuffer setFetchSize( int fetchSize ); + OutputBuffer setFetchSize(int fetchSize); /** * Print the lines as soon as they are produced and write to a PrintStream. + * * @param conn DB connection - * @param ps the PrintStream to be used, e.g: System.out + * @param ps the PrintStream to be used, e.g: System.out * @throws SQLException any sql errors */ void printAvailable(Connection conn, PrintStream ps) throws SQLException; /** * Print the lines as soon as they are produced and write to a list of PrintStreams. - * @param conn DB connection + * + * @param conn DB connection * @param printStreams the PrintStream list to be used, e.g: System.out, new PrintStream(new FileOutputStream) * @throws SQLException any sql errors */ @@ -37,7 +40,8 @@ public interface OutputBuffer { /** * Print the lines as soon as they are produced and call the callback passing the new line. - * @param conn DB connection + * + * @param conn DB connection * @param onLineFetched the callback to be called * @throws SQLException any sql errors */ @@ -45,6 +49,7 @@ public interface OutputBuffer { /** * Get all lines from output buffer and return it as a list of strings. + * * @param conn DB connection * @return the lines * @throws SQLException any sql errors diff --git a/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java b/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java index c4b1afe..094cf50 100644 --- a/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java +++ b/src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java @@ -12,7 +12,11 @@ public class OutputBufferProvider { - /** Returns an OutputBuffer compatible with the given databaseVersion + private OutputBufferProvider() { + } + + /** + * Returns an OutputBuffer compatible with the given databaseVersion * If we are at 3.1.0 or greater, returns an OutputBuffer based upon the information whether the Reporter has Output or not * * @param databaseVersion @@ -21,42 +25,41 @@ public class OutputBufferProvider { * @return * @throws SQLException */ - public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Reporter reporter, Connection conn ) throws SQLException { - OracleConnection oraConn = conn.unwrap(OracleConnection.class); + public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Reporter reporter, Connection conn) throws SQLException { + OracleConnection oraConn = conn.unwrap(OracleConnection.class); - try { - if (databaseVersion.isGreaterOrEqualThan(Version.V3_1_0)) { - if ( hasOutput(reporter, oraConn) ) { - return new DefaultOutputBuffer(reporter); - } - else { - return new NonOutputBuffer(reporter); - } - } - } - catch ( InvalidVersionException ignored ) { } + try { + if (databaseVersion.isGreaterOrEqualThan(Version.V3_1_0)) { + if (hasOutput(reporter, oraConn)) { + return new DefaultOutputBuffer(reporter); + } else { + return new NonOutputBuffer(reporter); + } + } + } catch (InvalidVersionException ignored) { + } - // If we couldn't find an appropriate OutputBuffer, return the Pre310-Compatibility-Buffer - return new CompatibilityOutputBufferPre310(reporter); + // If we couldn't find an appropriate OutputBuffer, return the Pre310-Compatibility-Buffer + return new CompatibilityOutputBufferPre310(reporter); } - private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) throws SQLException { + private static boolean hasOutput(Reporter reporter, OracleConnection oraConn) throws SQLException { String sql = "declare " + - " l_result int;" + - "begin " + - " begin " + - " execute immediate '" + - " begin " + - " :x := case ' || dbms_assert.simple_sql_name( ? ) || '() is of (ut_output_reporter_base) when true then 1 else 0 end;" + - " end;'" + - " using out l_result;" + - " end;" + - " ? := l_result;" + - "end;"; + " l_result int;" + + "begin " + + " begin " + + " execute immediate '" + + " begin " + + " :x := case ' || dbms_assert.simple_sql_name( ? ) || '() is of (ut_output_reporter_base) when true then 1 else 0 end;" + + " end;'" + + " using out l_result;" + + " end;" + + " ? := l_result;" + + "end;"; - try ( CallableStatement stmt = oraConn.prepareCall(sql)) { + try (CallableStatement stmt = oraConn.prepareCall(sql)) { stmt.setQueryTimeout(3); stmt.setString(1, reporter.getTypeName()); stmt.registerOutParameter(2, OracleTypes.INTEGER); @@ -66,7 +69,4 @@ private static boolean hasOutput( Reporter reporter, OracleConnection oraConn ) return result == 1; } } - - 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 3c0f7ff..74c9dec 100644 --- a/src/main/java/org/utplsql/api/reporter/CoreReporters.java +++ b/src/main/java/org/utplsql/api/reporter/CoreReporters.java @@ -3,7 +3,8 @@ import org.utplsql.api.Version; import org.utplsql.api.exception.InvalidVersionException; -/** This enum defines default reporters, added and maintained by the utPLSQL team, +/** + * This enum defines default reporters, added and maintained by the utPLSQL team, * and information since (and maybe until) which version they exist * * @author pesse @@ -22,7 +23,7 @@ public enum CoreReporters { private final Version since; private final Version until; - CoreReporters(Version since, Version until ) { + CoreReporters(Version since, Version until) { this.since = since; this.until = until; } @@ -35,18 +36,20 @@ public Version getUntil() { return until; } - /** Checks whether a CoreReporter is valid for the given databaseVersion + /** + * Checks whether a CoreReporter is valid for the given databaseVersion * * @param databaseVersion Database-Version * @return true or false */ - public boolean isAvailableFor( Version databaseVersion ) { + public boolean isAvailableFor(Version databaseVersion) { try { if ((since == null || databaseVersion.isGreaterOrEqualThan(since)) - && (until == null || databaseVersion.isLessOrEqualThan(until))) + && (until == null || databaseVersion.isLessOrEqualThan(until))) { return true; + } + } catch (InvalidVersionException ignored) { } - catch ( InvalidVersionException ignored ) { } return false; } diff --git a/src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java b/src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java index 4168332..f927b00 100644 --- a/src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java +++ b/src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java @@ -29,58 +29,16 @@ public CoverageHTMLReporter(String selfType, Object[] attributes) { super(selfType, attributes); } - @Override - protected void setAttributes(Object[] attributes) { - super.setAttributes(attributes); - - if ( attributes != null ) { - if ( attributes[3] != null ) - projectName = String.valueOf(attributes[3]); - else - projectName = null; - - if ( attributes[4] != null ) - assetsPath = String.valueOf(attributes[4]); - else - assetsPath = null; - } - } - - @Override - protected Object[] getAttributes() { - Object[] attributes = super.getAttributes(); - - attributes[3] = projectName; - attributes[4] = assetsPath; - - return attributes; - } - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public String getAssetsPath() { - return assetsPath; - } - - public void setAssetsPath(String assetsPath) { - this.assetsPath = assetsPath; - } - - /** Copies files from Classpath to a target directory. + /** + * Copies files from Classpath to a target directory. * Can omit the first x folders of the asset-path when copying to the target directory * - * @param assetPath Path of the asset in the classpath - * @param targetDirectory Target directory to copy the asset to + * @param assetPath Path of the asset in the classpath + * @param targetDirectory Target directory to copy the asset to * @param filterNumOfFolders Omits the first x folders of the path when copying the asset to the target directory * @throws IOException */ - private static void copyFileFromClasspath( Path assetPath, Path targetDirectory, int filterNumOfFolders ) throws IOException { + private static void copyFileFromClasspath(Path assetPath, Path targetDirectory, int filterNumOfFolders) throws IOException { Path assetStartPath = assetPath.subpath(filterNumOfFolders, assetPath.getNameCount()); Path targetAssetPath = targetDirectory.resolve(Paths.get(assetStartPath.toString())); @@ -90,11 +48,12 @@ private static void copyFileFromClasspath( Path assetPath, Path targetDirectory, try (InputStream is = CoverageHTMLReporter.class.getClassLoader() .getResourceAsStream(assetPath.toString()) ) { - Files.copy( is, targetAssetPath, StandardCopyOption.REPLACE_EXISTING); + Files.copy(is, targetAssetPath, StandardCopyOption.REPLACE_EXISTING); } } - /** Write the bundled assets necessary for the HTML Coverage report to a given targetPath + /** + * Write the bundled assets necessary for the HTML Coverage report to a given targetPath * * @param targetDirectory Directory where the assets should be stored * @throws RuntimeException @@ -106,14 +65,59 @@ public static void writeReportAssetsTo(Path targetDirectory) throws RuntimeExcep List paths = ResourceUtil.getListOfChildren(Paths.get("CoverageHTMLReporter"), true); - paths.forEach((ThrowingConsumer) p -> copyFileFromClasspath(p, targetDirectory, 1) ); - } - catch ( IOException | URISyntaxException e ) { + paths.forEach((ThrowingConsumer) p -> copyFileFromClasspath(p, targetDirectory, 1)); + } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } } - /** Functional Interface just to throw Exception from Consumer + @Override + protected Object[] getAttributes() { + Object[] attributes = super.getAttributes(); + + attributes[3] = projectName; + attributes[4] = assetsPath; + + return attributes; + } + + @Override + protected void setAttributes(Object[] attributes) { + super.setAttributes(attributes); + + if (attributes != null) { + if (attributes[3] != null) { + projectName = String.valueOf(attributes[3]); + } else { + projectName = null; + } + + if (attributes[4] != null) { + assetsPath = String.valueOf(attributes[4]); + } else { + assetsPath = null; + } + } + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getAssetsPath() { + return assetsPath; + } + + public void setAssetsPath(String assetsPath) { + this.assetsPath = assetsPath; + } + + /** + * Functional Interface just to throw Exception from Consumer * * @param */ @@ -129,6 +133,6 @@ default void accept(final T elem) { } } - void acceptThrows( T t ) throws IOException; + void acceptThrows(T t) throws IOException; } } diff --git a/src/main/java/org/utplsql/api/reporter/DefaultReporter.java b/src/main/java/org/utplsql/api/reporter/DefaultReporter.java index 073115d..b478355 100644 --- a/src/main/java/org/utplsql/api/reporter/DefaultReporter.java +++ b/src/main/java/org/utplsql/api/reporter/DefaultReporter.java @@ -5,18 +5,19 @@ import java.sql.SQLException; -/** This is a basic Reporter implementation, using ORAData interface +/** + * This is a basic Reporter implementation, using ORAData interface * * @author pesse */ public class DefaultReporter extends Reporter { - public DefaultReporter(String typeName, Object[] attributes ) { + public DefaultReporter(String typeName, Object[] attributes) { super(typeName, attributes); } @Override - protected void initOutputBuffer( OracleConnection oraConn, CompatibilityProxy compatibilityProxy ) throws SQLException { + protected void initOutputBuffer(OracleConnection oraConn, CompatibilityProxy compatibilityProxy) throws SQLException { outputBuffer = compatibilityProxy.getOutputBuffer(this, oraConn); } } diff --git a/src/main/java/org/utplsql/api/reporter/DefaultReporterFactoryMethodRegistrator.java b/src/main/java/org/utplsql/api/reporter/DefaultReporterFactoryMethodRegistrator.java index 8760f55..f1880df 100644 --- a/src/main/java/org/utplsql/api/reporter/DefaultReporterFactoryMethodRegistrator.java +++ b/src/main/java/org/utplsql/api/reporter/DefaultReporterFactoryMethodRegistrator.java @@ -2,13 +2,14 @@ import org.utplsql.api.compatibility.CompatibilityProxy; -/** Helper-class which registers default ReporterFactoryMethods based on the given databaseVersion +/** + * Helper-class which registers default ReporterFactoryMethods based on the given databaseVersion * * @author pesse */ class DefaultReporterFactoryMethodRegistrator { - public static void registerDefaultReporters(ReporterFactory reporterFactory, CompatibilityProxy compatibilityProxy ) { + public static void registerDefaultReporters(ReporterFactory reporterFactory, CompatibilityProxy compatibilityProxy) { // At the moment we don't have version-specific reporters which need a special MethodFactory reporterFactory.registerReporterFactoryMethod(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), DocumentationReporter::new, "Provides additional properties lvl and failed"); diff --git a/src/main/java/org/utplsql/api/reporter/DocumentationReporter.java b/src/main/java/org/utplsql/api/reporter/DocumentationReporter.java index 19edd01..6e36613 100644 --- a/src/main/java/org/utplsql/api/reporter/DocumentationReporter.java +++ b/src/main/java/org/utplsql/api/reporter/DocumentationReporter.java @@ -8,23 +8,13 @@ public class DocumentationReporter extends DefaultReporter { private int failed; public DocumentationReporter() { - super( CoreReporters.UT_DOCUMENTATION_REPORTER.name(), null ); + super(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), null); } - public DocumentationReporter(String selfType, Object[] attributes ) { + public DocumentationReporter(String selfType, Object[] attributes) { super(selfType, attributes); } - @Override - protected void setAttributes(Object[] attributes) { - super.setAttributes(attributes); - - if ( attributes != null ) { - lvl = ((BigDecimal)attributes[3]).intValue(); - failed = ((BigDecimal)attributes[4]).intValue(); - } - } - @Override protected Object[] getAttributes() { Object[] attributes = super.getAttributes(); @@ -33,6 +23,16 @@ protected Object[] getAttributes() { return attributes; } + @Override + protected void setAttributes(Object[] attributes) { + super.setAttributes(attributes); + + if (attributes != null) { + lvl = ((BigDecimal) attributes[3]).intValue(); + failed = ((BigDecimal) attributes[4]).intValue(); + } + } + public int getLvl() { return lvl; } diff --git a/src/main/java/org/utplsql/api/reporter/Reporter.java b/src/main/java/org/utplsql/api/reporter/Reporter.java index 639e0c6..6edd853 100644 --- a/src/main/java/org/utplsql/api/reporter/Reporter.java +++ b/src/main/java/org/utplsql/api/reporter/Reporter.java @@ -14,44 +14,41 @@ import java.sql.Connection; import java.sql.SQLException; -/** This is a basic Reporter implementation, using ORAData interface +/** + * This is a basic Reporter implementation, using ORAData interface * * @author pesse */ public abstract class Reporter implements ORAData { private static final Logger logger = LoggerFactory.getLogger(Reporter.class); - + protected OutputBuffer outputBuffer; private String selfType; private String id; private Object[] attributes; private boolean init = false; - protected OutputBuffer outputBuffer; - public Reporter( String typeName, Object[] attributes ) { + public Reporter(String typeName, Object[] attributes) { setTypeName(typeName); - setAttributes( attributes ); - } - - protected void setTypeName( String typeName ) { - this.selfType = typeName.replaceAll("[^0-9a-zA-Z_\\.]", ""); + setAttributes(attributes); } + public Reporter init(Connection con, CompatibilityProxy compatibilityProxy, ReporterFactory reporterFactory) throws SQLException { - public Reporter init(Connection con, CompatibilityProxy compatibilityProxy, ReporterFactory reporterFactory ) throws SQLException { - - if ( compatibilityProxy == null ) + if (compatibilityProxy == null) { compatibilityProxy = new CompatibilityProxy(con); - if ( reporterFactory == null ) + } + if (reporterFactory == null) { reporterFactory = new ReporterFactory(); + } OracleConnection oraConn = con.unwrap(OracleConnection.class); - initDbReporter( oraConn, reporterFactory ); + initDbReporter(oraConn, reporterFactory); init = true; - initOutputBuffer( oraConn, compatibilityProxy); + initOutputBuffer(oraConn, compatibilityProxy); return this; } @@ -60,16 +57,17 @@ public Reporter init(Connection con) throws SQLException { return init(con, null, null); } - protected abstract void initOutputBuffer( OracleConnection oraConn, CompatibilityProxy compatibilityProxy ) throws SQLException; + protected abstract void initOutputBuffer(OracleConnection oraConn, CompatibilityProxy compatibilityProxy) throws SQLException; - /** Initializes the Reporter from database + /** + * Initializes the Reporter from database * This is necessary because we set up DefaultOutputBuffer (and maybe other stuff) we don't want to know and care about * in the java API. Let's just do the instantiation of the Reporter in the database and map it into this object. * * @param oraConn * @throws SQLException */ - private void initDbReporter( OracleConnection oraConn, ReporterFactory reporterFactory ) throws SQLException { + private void initDbReporter(OracleConnection oraConn, ReporterFactory reporterFactory) throws SQLException { OracleCallableStatement callableStatement = (OracleCallableStatement) oraConn.prepareCall("{? = call " + selfType + "()}"); callableStatement.registerOutParameter(1, OracleTypes.STRUCT, "UT_REPORTER_BASE"); callableStatement.execute(); @@ -81,17 +79,17 @@ private void initDbReporter( OracleConnection oraConn, ReporterFactory reporterF logger.debug("Database-reporter initialized, Type: {}, ID: {}", selfType, id); } - protected void setAttributes(Object[] attributes ) { + protected Object[] getAttributes() { + return attributes; + } + + protected void setAttributes(Object[] attributes) { if (attributes != null) { - this.id = DatatypeConverter.printHexBinary((byte[])attributes[1]); + this.id = DatatypeConverter.printHexBinary((byte[]) attributes[1]); } this.attributes = attributes; } - protected Object[] getAttributes() { - return attributes; - } - public boolean isInit() { return init; } @@ -100,14 +98,17 @@ public String getTypeName() { return this.selfType; } + protected void setTypeName(String typeName) { + this.selfType = typeName.replaceAll("[^0-9a-zA-Z_\\.]", ""); + } + public String getId() { return this.id; } - public Datum toDatum(Connection c) throws SQLException - { - return (Datum)c.createStruct(getTypeName(), getAttributes()); + public Datum toDatum(Connection c) throws SQLException { + return (Datum) c.createStruct(getTypeName(), getAttributes()); } public OutputBuffer getOutputBuffer() { diff --git a/src/main/java/org/utplsql/api/reporter/ReporterFactory.java b/src/main/java/org/utplsql/api/reporter/ReporterFactory.java index 510896b..4b733e3 100644 --- a/src/main/java/org/utplsql/api/reporter/ReporterFactory.java +++ b/src/main/java/org/utplsql/api/reporter/ReporterFactory.java @@ -12,67 +12,87 @@ import java.util.Map; import java.util.function.BiFunction; -/** This class manages the instantiation of reporters. +/** + * This class manages the instantiation of reporters. * One can register a supplier method for a specific name which will then be callable via createReporter(name) - * + *

* Use the static createEmpty or createDefault methods to get a new instance. * We don't allow direct instantiation because we want *

    - *
  • Register default ReporterFactoryMethods for Core-Reporters
  • - *
  • Be able to add more than one ReporterFactory implementation due to backwards-compatibility in future
  • + *
  • Register default ReporterFactoryMethods for Core-Reporters
  • + *
  • Be able to add more than one ReporterFactory implementation due to backwards-compatibility in future
  • *
* * @author pesse */ public final class ReporterFactory implements ORADataFactory { - public static class ReporterFactoryMethodInfo { - public ReporterFactoryMethodInfo(BiFunction factoryMethod, String description) { - this.factoryMethod = factoryMethod; - this.description = description; - } - public final BiFunction factoryMethod; - public final String description; + private final Map reportFactoryMethodMap = new HashMap<>(); + + ReporterFactory() { } - private final Map reportFactoryMethodMap = new HashMap<>(); + /** + * Returns a new instance of an empty ReporterFactory with no registered ReporterFactoryMethods + * Normally, you should be using createDefault-method instead. + * + * @return a new ReporterFactory instance + */ + public static ReporterFactory createEmpty() { + return new ReporterFactory(); + } - ReporterFactory() { } + /** + * Returns a new instance of a ReporterFactory with the default ReporterFactoryMethods registered. + * This can depend on the version of utPLSQL, therefore you have to provide a CompatibilityProxy + * + * @param proxy Compatibility proxy + * @return a new ReporterFactory instance with all default ReporterFactoryMethods registered + */ + public static ReporterFactory createDefault(CompatibilityProxy proxy) { + ReporterFactory reporterFactory = new ReporterFactory(); + DefaultReporterFactoryMethodRegistrator.registerDefaultReporters(reporterFactory, proxy); + return reporterFactory; + } - /** Registers a creation method for a specified reporter name. Overrides eventually existing creation method + /** + * Registers a creation method for a specified reporter name. Overrides eventually existing creation method * - * @param reporterName the reporter's name to register + * @param reporterName the reporter's name to register * @param factoryMethod the method which will return the reporter - * @param description the description of the reporter + * @param description the description of the reporter * @return Object with information about the registered reporter */ public synchronized ReporterFactoryMethodInfo registerReporterFactoryMethod(String reporterName, BiFunction factoryMethod, String description) { return reportFactoryMethodMap.put(reporterName.toUpperCase(), new ReporterFactoryMethodInfo(factoryMethod, description)); } - /** Unregisters a specified reporter name. + /** + * Unregisters a specified reporter name. * * @param reporterName the reporter's name to unregister * @return information about the reporter which was previously registered or null */ - public synchronized ReporterFactoryMethodInfo unregisterReporterFactoryMethod(String reporterName ) { + public synchronized ReporterFactoryMethodInfo unregisterReporterFactoryMethod(String reporterName) { return reportFactoryMethodMap.remove(reporterName.toUpperCase()); } - /** Checks whether a given reporter has a registered FactoryMethod or not + /** + * Checks whether a given reporter has a registered FactoryMethod or not * * @param reporterName the reporter's name * @return true or false */ - public synchronized boolean hasRegisteredFactoryMethodFor( String reporterName ) { + public synchronized boolean hasRegisteredFactoryMethodFor(String reporterName) { return reportFactoryMethodMap.containsKey(reporterName.toUpperCase()); } - /** Returns a new reporter of the given name. + /** + * Returns a new reporter of the given name. * If no specific ReporterFactoryMethod is registered, returns a default {Reporter} * * @param reporterName the reporter's name to create a new instance of - * @param attributes attributes from STRUCT + * @param attributes attributes from STRUCT * @return A reporter */ public Reporter createReporter(String reporterName, @Nullable Object[] attributes) { @@ -80,29 +100,33 @@ public Reporter createReporter(String reporterName, @Nullable Object[] attribute reporterName = reporterName.toUpperCase(); BiFunction supplier = DefaultReporter::new; - if ( reportFactoryMethodMap.containsKey(reporterName)) { + if (reportFactoryMethodMap.containsKey(reporterName)) { ReporterFactoryMethodInfo ri = reportFactoryMethodMap.get(reporterName); - if (ri == null) + if (ri == null) { throw new RuntimeException("ReporterFactoryMethodInfo for " + reporterName + " was null"); + } supplier = ri.factoryMethod; } - if ( supplier == null ) + if (supplier == null) { throw new RuntimeException("No factory method for " + reporterName); + } - return supplier.apply( reporterName, attributes ); + return supplier.apply(reporterName, attributes); } - /** Returns a new reporter of the given name (or should do so). + /** + * Returns a new reporter of the given name (or should do so). * If no specific ReporterFactoryMethod is registered, returns a default {Reporter} */ - public Reporter createReporter( String reporterName ) { + public Reporter createReporter(String reporterName) { return createReporter(reporterName, null); } - /** Returns a set of all registered reporter's names + /** + * Returns a set of all registered reporter's names * * @return Set of reporter names */ @@ -118,32 +142,21 @@ public Map getRegisteredReporterInfo() { @Override public ORAData create(Datum d, int sqlType) throws SQLException { if (d == null) return null; - if ( d instanceof Struct) { - String sqlName = ((Struct)d).getSQLTypeName(); - return createReporter(sqlName, ((Struct)d).getAttributes()); + if (d instanceof Struct) { + String sqlName = ((Struct) d).getSQLTypeName(); + return createReporter(sqlName, ((Struct) d).getAttributes()); } return null; } - /** Returns a new instance of an empty ReporterFactory with no registered ReporterFactoryMethods - * Normally, you should be using createDefault-method instead. - * - * @return a new ReporterFactory instance - */ - public static ReporterFactory createEmpty() { - return new ReporterFactory(); - } + public static class ReporterFactoryMethodInfo { + public final BiFunction factoryMethod; + public final String description; - /** Returns a new instance of a ReporterFactory with the default ReporterFactoryMethods registered. - * This can depend on the version of utPLSQL, therefore you have to provide a CompatibilityProxy - * - * @param proxy Compatibility proxy - * @return a new ReporterFactory instance with all default ReporterFactoryMethods registered - */ - public static ReporterFactory createDefault(CompatibilityProxy proxy) { - ReporterFactory reporterFactory = new ReporterFactory(); - DefaultReporterFactoryMethodRegistrator.registerDefaultReporters(reporterFactory, proxy); - return reporterFactory; + public ReporterFactoryMethodInfo(BiFunction factoryMethod, String description) { + this.factoryMethod = factoryMethod; + this.description = description; + } } } 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 11a8798..bbab916 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/AbstractReporterInspector.java @@ -4,12 +4,12 @@ import java.sql.Connection; -abstract class AbstractReporterInspector implements ReporterInspector { +abstract class AbstractReporterInspector implements ReporterInspector { protected final ReporterFactory reporterFactory; protected final Connection connection; - AbstractReporterInspector(ReporterFactory reporterFactory, Connection conn ) { + AbstractReporterInspector(ReporterFactory reporterFactory, Connection conn) { this.reporterFactory = reporterFactory; this.connection = conn; } 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 a987bdd..fb805d5 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInfo.java @@ -1,20 +1,17 @@ package org.utplsql.api.reporter.inspect; -/** Holds information about utPLSQL Reporter-Types +/** + * Holds information about utPLSQL Reporter-Types * * @author pesse */ public class ReporterInfo { - public enum Type { - SQL, JAVA, SQL_WITH_JAVA - } - private final String name; private final Type type; private final String description; - ReporterInfo( String name, Type type, String description ) { + ReporterInfo(String name, Type type, String description) { this.name = name; this.type = type; this.description = description; @@ -31,4 +28,8 @@ public Type getType() { public String getDescription() { return description; } + + public enum Type { + SQL, JAVA, SQL_WITH_JAVA + } } 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 436b939..bf4c287 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java @@ -19,12 +19,6 @@ */ public interface ReporterInspector { - List getReporterInfos(); - - 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 * @@ -37,10 +31,17 @@ static ReporterInspector create(ReporterFactory reporterFactory, Connection conn CompatibilityProxy proxy = new CompatibilityProxy(conn); - if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_0)) + if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_0)) { return new ReporterInspector310(reporterFactory, conn); - else + } else { return new ReporterInspectorPre310(reporterFactory, conn); + } + } + + List getReporterInfos(); + + default Map getReporterInfoMap() { + return getReporterInfos().stream().collect(Collectors.toMap(ReporterInfo::getName, Function.identity())); } } 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 cd1b8ea..091e0f4 100644 --- a/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java +++ b/src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector310.java @@ -13,7 +13,8 @@ import java.sql.SQLException; import java.util.*; -/** ReporterInspector for v3.1.0 upwards +/** + * ReporterInspector for v3.1.0 upwards * * @author pesse */ @@ -22,15 +23,16 @@ class ReporterInspector310 extends AbstractReporterInspector { private final Map registeredReporterFactoryMethods; private final Set infos; - ReporterInspector310(ReporterFactory reporterFactory, Connection conn ) throws SQLException { + ReporterInspector310(ReporterFactory reporterFactory, Connection conn) throws SQLException { super(reporterFactory, conn); registeredReporterFactoryMethods = reporterFactory.getRegisteredReporterInfo(); 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()) + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { reporterInfos.add(getReporterInfo(rs.getString(1))); + } } } this.infos = reporterInfos; @@ -42,13 +44,13 @@ public List getReporterInfos() { return new ArrayList<>(infos); } - private ReporterInfo getReporterInfo(String reporterNameWithOwner ) throws SQLException { - String reporterName = reporterNameWithOwner.substring(reporterNameWithOwner.indexOf(".")+1).toUpperCase(); + private ReporterInfo getReporterInfo(String reporterNameWithOwner) throws SQLException { + String reporterName = reporterNameWithOwner.substring(reporterNameWithOwner.indexOf(".") + 1).toUpperCase(); ReporterInfo.Type type = ReporterInfo.Type.SQL; String description = getDescription(reporterName); - if ( registeredReporterFactoryMethods.containsKey(reporterName) ) { + if (registeredReporterFactoryMethods.containsKey(reporterName)) { type = ReporterInfo.Type.SQL_WITH_JAVA; description += "\n" + registeredReporterFactoryMethods.get(reporterName); } @@ -56,7 +58,7 @@ private ReporterInfo getReporterInfo(String reporterNameWithOwner ) throws SQLEx return new ReporterInfo(reporterName, type, description); } - private String getDescription( String reporterName ) throws SQLException { + 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/testRunner/AbstractTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java index 147065a..dbd5086 100644 --- a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java @@ -21,8 +21,8 @@ abstract class AbstractTestRunnerStatement implements TestRunnerStatement { protected final TestRunnerOptions options; - private final Connection conn; protected final CallableStatement callableStatement; + private final Connection conn; public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { this.options = options; @@ -95,7 +95,8 @@ public void execute() throws SQLException { @Override public void close() throws SQLException { - if (callableStatement != null) + if (callableStatement != null) { callableStatement.close(); + } } } diff --git a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java index 05a05ce..8625f95 100644 --- a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java @@ -5,15 +5,16 @@ import java.sql.Connection; import java.sql.SQLException; -/** Provides the call to run tests for the most actual Framework version. +/** + * Provides the call to run tests for the most actual Framework version. * Includes fail on error * - * @author pesse + * @author pesse */ class ActualTestRunnerStatement extends AbstractTestRunnerStatement { - public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException { - super( options, connection); + public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException { + super(options, connection); } @Override diff --git a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java index b741459..d2d53cb 100644 --- a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java @@ -5,7 +5,8 @@ import java.sql.Connection; import java.sql.SQLException; -/** TestRunner-Statement for Framework version before 3.0.3 +/** + * TestRunner-Statement for Framework version before 3.0.3 * Does not know about failOnErrors option * * @author pesse diff --git a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java index c8e5f5f..129413b 100644 --- a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java @@ -5,15 +5,16 @@ import java.sql.Connection; import java.sql.SQLException; -/** TestRunner-Statement for Framework version before 3.0.3 +/** + * TestRunner-Statement for Framework version before 3.0.3 * Does not know about client character set * - * @author pesse + * @author pesse */ class Pre312TestRunnerStatement extends AbstractTestRunnerStatement { - public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException { - super( options, connection); + public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException { + super(options, connection); } @Override diff --git a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java index eb8722f..77a9204 100644 --- a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java +++ b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java @@ -7,38 +7,43 @@ import java.sql.Connection; import java.sql.SQLException; -/** Provides different implementations of TestRunnerStatement based on the version of the database framework +/** + * Provides different implementations of TestRunnerStatement based on the version of the database framework * * @author pesse */ public class TestRunnerStatementProvider { - /** Returns the TestRunnerStatement-implementation compatible with the given databaseVersion. + private TestRunnerStatementProvider() { + throw new UnsupportedOperationException(); + } + + /** + * Returns the TestRunnerStatement-implementation compatible with the given databaseVersion. * * @param databaseVersion Version of the database framework - * @param options TestRunnerOptions to be used - * @param conn Active Connection + * @param options TestRunnerOptions to be used + * @param conn Active Connection * @return TestRunnerStatment compatible with the database framework * @throws SQLException */ - public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn ) throws SQLException { + public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn) throws SQLException { AbstractTestRunnerStatement stmt = null; try { - if (databaseVersion.isLessThan(Version.V3_0_3)) + if (databaseVersion.isLessThan(Version.V3_0_3)) { stmt = new Pre303TestRunnerStatement(options, conn); - else if (databaseVersion.isLessThan(Version.V3_1_2)) + } else if (databaseVersion.isLessThan(Version.V3_1_2)) { stmt = new Pre312TestRunnerStatement(options, conn); + } - } catch ( InvalidVersionException ignored ) {} + } catch (InvalidVersionException ignored) { + } - if ( stmt == null ) + if (stmt == null) { stmt = new ActualTestRunnerStatement(options, conn); + } return stmt; } - - private TestRunnerStatementProvider() { - throw new UnsupportedOperationException(); - } } diff --git a/src/test/java/org/utplsql/api/AbstractDatabaseTest.java b/src/test/java/org/utplsql/api/AbstractDatabaseTest.java index 4332721..393c31e 100644 --- a/src/test/java/org/utplsql/api/AbstractDatabaseTest.java +++ b/src/test/java/org/utplsql/api/AbstractDatabaseTest.java @@ -14,8 +14,9 @@ public abstract class AbstractDatabaseTest { private static String sUrl; private static String sUser; private static String sPass; + static { - sUrl = EnvironmentVariableUtil.getEnvValue("DB_URL", "192.168.99.100:1521:XE"); + sUrl = EnvironmentVariableUtil.getEnvValue("DB_URL", "192.168.99.100:1521:XE"); sUser = EnvironmentVariableUtil.getEnvValue("DB_USER", "app"); sPass = EnvironmentVariableUtil.getEnvValue("DB_PASS", "app"); } @@ -23,6 +24,10 @@ public abstract class AbstractDatabaseTest { private Connection conn; private List connectionList = new ArrayList<>(); + public static String getUser() { + return sUser; + } + @BeforeEach public void setupConnection() throws SQLException { conn = newConnection(); @@ -38,13 +43,13 @@ protected synchronized Connection newConnection() throws SQLException { return conn; } - public static String getUser() { - return sUser; - } - @AfterEach public void teardownConnection() { - for (Connection conn : connectionList) - try { conn.close(); } catch (SQLException ignored) {} + for (Connection conn : connectionList) { + try { + conn.close(); + } catch (SQLException ignored) { + } + } } } diff --git a/src/test/java/org/utplsql/api/EnvironmentVariableUtilTest.java b/src/test/java/org/utplsql/api/EnvironmentVariableUtilTest.java index 8a0487f..e437cd1 100644 --- a/src/test/java/org/utplsql/api/EnvironmentVariableUtilTest.java +++ b/src/test/java/org/utplsql/api/EnvironmentVariableUtilTest.java @@ -20,8 +20,9 @@ void testGetVariableFromEnvironment() { .filter((e) -> !props.contains(e.getKey()) && e.getValue() != null && !e.getValue().isEmpty()) .findFirst(); - if ( !envVariable.isPresent() ) - fail ("Can't test for there is no environment variable not overridden by property"); + if (!envVariable.isPresent()) { + fail("Can't test for there is no environment variable not overridden by property"); + } assertEquals(envVariable.get().getValue(), EnvironmentVariableUtil.getEnvValue(envVariable.get().getKey())); } @@ -36,7 +37,7 @@ void testGetVariableFromProperty() { @Test void testGetVariableFromDefault() { - assertEquals("defaultValue", EnvironmentVariableUtil.getEnvValue("RANDOM"+String.valueOf(System.currentTimeMillis()), "defaultValue")); + assertEquals("defaultValue", EnvironmentVariableUtil.getEnvValue("RANDOM" + String.valueOf(System.currentTimeMillis()), "defaultValue")); } } \ No newline at end of file diff --git a/src/test/java/org/utplsql/api/FileMapperIT.java b/src/test/java/org/utplsql/api/FileMapperIT.java index 0db0163..20ff1b4 100644 --- a/src/test/java/org/utplsql/api/FileMapperIT.java +++ b/src/test/java/org/utplsql/api/FileMapperIT.java @@ -31,8 +31,9 @@ void testFileMapper() throws SQLException { List fileMappings = FileMapper.buildFileMappingList(getConnection(), mapperOptions); - if (fileMappings.size() != 2) + if (fileMappings.size() != 2) { fail("Wrong mapping list size."); + } assertMapping(fileMappings.get(0), "APP", "AWARD_BONUS", "PROCEDURE"); assertMapping(fileMappings.get(1), "APP", "BETWNSTR", "FUNCTION"); diff --git a/src/test/java/org/utplsql/api/OptionalFeaturesIT.java b/src/test/java/org/utplsql/api/OptionalFeaturesIT.java index dad6263..c7ce27e 100644 --- a/src/test/java/org/utplsql/api/OptionalFeaturesIT.java +++ b/src/test/java/org/utplsql/api/OptionalFeaturesIT.java @@ -22,10 +22,11 @@ void failOnError() throws SQLException, InvalidVersionException { boolean available = OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(getConnection()); - if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) + if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) { assertTrue(available); - else + } else { assertFalse(available); + } } @Test @@ -33,10 +34,11 @@ void frameworkCompatibilityCheck() throws SQLException, InvalidVersionException boolean available = OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(getConnection()); - if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) + if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) { assertTrue(available); - else + } else { assertFalse(available); + } } @Test @@ -44,9 +46,10 @@ void customReporters() throws SQLException, InvalidVersionException { boolean available = OptionalFeatures.CUSTOM_REPORTERS.isAvailableFor(getConnection()); - if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_0)) + if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_0)) { assertTrue(available); - else + } else { assertFalse(available); + } } } diff --git a/src/test/java/org/utplsql/api/OutputBufferIT.java b/src/test/java/org/utplsql/api/OutputBufferIT.java index 18ee3ee..c6fea1f 100644 --- a/src/test/java/org/utplsql/api/OutputBufferIT.java +++ b/src/test/java/org/utplsql/api/OutputBufferIT.java @@ -88,11 +88,13 @@ void printAvailableLines() throws SQLException { Object res1 = task1.get(); Object res2 = task2.get(); - if (res1 instanceof Exception) + if (res1 instanceof Exception) { fail((Exception) res1); + } - if (res2 instanceof Exception) + if (res2 instanceof Exception) { fail((Exception) res2); + } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } @@ -129,7 +131,7 @@ void getOutputFromSonarReporter() throws SQLException { void sonarReporterHasEncodingSet() throws SQLException, InvalidVersionException { CompatibilityProxy proxy = new CompatibilityProxy(newConnection()); - if ( proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_2)) { + if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_2)) { Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(getConnection()); TestRunner tr = new TestRunner() diff --git a/src/test/java/org/utplsql/api/ReporterInspectorIT.java b/src/test/java/org/utplsql/api/ReporterInspectorIT.java index b076351..367d9d1 100644 --- a/src/test/java/org/utplsql/api/ReporterInspectorIT.java +++ b/src/test/java/org/utplsql/api/ReporterInspectorIT.java @@ -31,15 +31,15 @@ void testGetReporterInfo() throws SQLException, InvalidVersionException { Map infos = inspector.getReporterInfoMap(); - assertEquals( infos.get(CoreReporters.UT_COVERAGE_HTML_REPORTER.name()).getType(), ReporterInfo.Type.SQL_WITH_JAVA ); - assertEquals( infos.get(CoreReporters.UT_COVERAGE_SONAR_REPORTER.name()).getType(), ReporterInfo.Type.SQL ); - assertEquals( infos.get(CoreReporters.UT_COVERALLS_REPORTER.name()).getType(), ReporterInfo.Type.SQL ); - assertEquals( infos.get(CoreReporters.UT_DOCUMENTATION_REPORTER.name()).getType(), ReporterInfo.Type.SQL_WITH_JAVA ); - assertEquals( infos.get(CoreReporters.UT_SONAR_TEST_REPORTER.name()).getType(), ReporterInfo.Type.SQL); - assertEquals( infos.get(CoreReporters.UT_TEAMCITY_REPORTER.name()).getType(), ReporterInfo.Type.SQL); - assertEquals( infos.get(CoreReporters.UT_XUNIT_REPORTER.name()).getType(), ReporterInfo.Type.SQL); - - if ( CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.isAvailableFor(proxy.getDatabaseVersion())) { + assertEquals(infos.get(CoreReporters.UT_COVERAGE_HTML_REPORTER.name()).getType(), ReporterInfo.Type.SQL_WITH_JAVA); + assertEquals(infos.get(CoreReporters.UT_COVERAGE_SONAR_REPORTER.name()).getType(), ReporterInfo.Type.SQL); + assertEquals(infos.get(CoreReporters.UT_COVERALLS_REPORTER.name()).getType(), ReporterInfo.Type.SQL); + assertEquals(infos.get(CoreReporters.UT_DOCUMENTATION_REPORTER.name()).getType(), ReporterInfo.Type.SQL_WITH_JAVA); + assertEquals(infos.get(CoreReporters.UT_SONAR_TEST_REPORTER.name()).getType(), ReporterInfo.Type.SQL); + assertEquals(infos.get(CoreReporters.UT_TEAMCITY_REPORTER.name()).getType(), ReporterInfo.Type.SQL); + assertEquals(infos.get(CoreReporters.UT_XUNIT_REPORTER.name()).getType(), ReporterInfo.Type.SQL); + + if (CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.isAvailableFor(proxy.getDatabaseVersion())) { assertEquals(infos.get(CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.name()).getType(), ReporterInfo.Type.SQL); } } diff --git a/src/test/java/org/utplsql/api/TestRunnerIT.java b/src/test/java/org/utplsql/api/TestRunnerIT.java index 95368ca..414b9f9 100644 --- a/src/test/java/org/utplsql/api/TestRunnerIT.java +++ b/src/test/java/org/utplsql/api/TestRunnerIT.java @@ -26,7 +26,8 @@ void runWithDefaultParameters() throws SQLException { } - /** This can only be run against versions >= 3.0.3 + /** + * This can only be run against versions >= 3.0.3 */ @Test void runWithoutCompatibilityCheck() throws SQLException, InvalidVersionException { @@ -55,7 +56,8 @@ void runWithManyReporters() throws SQLException { } - /** This can only be tested on frameworks >= 3.0.3 + /** + * This can only be tested on frameworks >= 3.0.3 */ @Test void failOnErrors() throws SQLException, InvalidVersionException { diff --git a/src/test/java/org/utplsql/api/VersionObjectTest.java b/src/test/java/org/utplsql/api/VersionObjectTest.java index d0f4ed4..22dcd24 100644 --- a/src/test/java/org/utplsql/api/VersionObjectTest.java +++ b/src/test/java/org/utplsql/api/VersionObjectTest.java @@ -11,10 +11,10 @@ class VersionObjectTest { void versionPatternRecognitionFull() { Version v = Version.create("v3.1.3.1234"); - assertEquals(3, (long)v.getMajor()); - assertEquals(1, (long)v.getMinor()); - assertEquals(3, (long)v.getBugfix()); - assertEquals(1234, (long)v.getBuild()); + assertEquals(3, (long) v.getMajor()); + assertEquals(1, (long) v.getMinor()); + assertEquals(3, (long) v.getBugfix()); + assertEquals(1234, (long) v.getBuild()); assertTrue(v.isValid()); assertEquals("3.1.3.1234", v.getNormalizedString()); } @@ -23,10 +23,10 @@ void versionPatternRecognitionFull() { void versionPatternRecognitionDevelop() { Version v = Version.create("v3.1.3.2140-develop"); - assertEquals(3, (long)v.getMajor()); - assertEquals(1, (long)v.getMinor()); - assertEquals(3, (long)v.getBugfix()); - assertEquals(2140, (long)v.getBuild()); + assertEquals(3, (long) v.getMajor()); + assertEquals(1, (long) v.getMinor()); + assertEquals(3, (long) v.getBugfix()); + assertEquals(2140, (long) v.getBuild()); assertTrue(v.isValid()); assertEquals("3.1.3.2140", v.getNormalizedString()); } @@ -35,8 +35,8 @@ void versionPatternRecognitionDevelop() { void versionPatternRecognitionPartial() { Version v = Version.create("3.1.etc"); - assertEquals(3, (long)v.getMajor()); - assertEquals(1, (long)v.getMinor()); + assertEquals(3, (long) v.getMajor()); + assertEquals(1, (long) v.getMinor()); assertNull(v.getBugfix()); assertNull(v.getBuild()); assertTrue(v.isValid()); @@ -56,8 +56,7 @@ void versionPatternRecognitionInvalid() { } @Test - void versionCompareTo() - { + void versionCompareTo() { Version base = Version.create("2.3.4.5"); // Less than @@ -80,8 +79,7 @@ void versionCompareTo() } @Test - void isGreaterOrEqualThan() throws InvalidVersionException - { + void isGreaterOrEqualThan() throws InvalidVersionException { Version base = Version.create("2.3.4.5"); assertTrue(base.isGreaterOrEqualThan(Version.create("1"))); @@ -101,30 +99,26 @@ void isGreaterOrEqualThan() throws InvalidVersionException } @Test - void isGreaterOrEqualThanFails() - { + void isGreaterOrEqualThanFails() { // Given version is invalid try { Version.create("2.3.4.5").isGreaterOrEqualThan(Version.create("aerfvf")); fail("Given Version is invalid - not recognized"); - } - catch ( InvalidVersionException ignored ) { + } catch (InvalidVersionException ignored) { } // Base version is invalid try { Version.create("erefs").isGreaterOrEqualThan(Version.create("1.2.3")); fail("Base version is invalid - not recognized"); - } - catch ( InvalidVersionException ignored ) { + } catch (InvalidVersionException ignored) { } // Both versions are invalid try { Version.create("erefs").isGreaterOrEqualThan(Version.create("aerfvf")); fail("Both versions are invalid - not recognized"); - } - catch ( InvalidVersionException ignored ) { + } catch (InvalidVersionException ignored) { } } } diff --git a/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java b/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java index 31abc01..41dd399 100644 --- a/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java +++ b/src/test/java/org/utplsql/api/reporter/CoverageHTMLReporterAssetTest.java @@ -14,6 +14,27 @@ class CoverageHTMLReporterAssetTest { private static final String TEST_FOLDER = "__testAssets"; + @AfterAll + static void clearTestAssetsFolder() { + try { + Files.walkFileTree(Paths.get(TEST_FOLDER), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + } + private void testFileExists(Path filePath) { File f = new File(filePath.toUri()); @@ -56,25 +77,4 @@ void writeReporterAssetsTo() throws RuntimeException { testFileExists(targetPath.resolve(Paths.get("magnify.png"))); } - - @AfterAll - static void clearTestAssetsFolder() { - try { - Files.walkFileTree(Paths.get(TEST_FOLDER), new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - e.printStackTrace(); - } - } } From d8ab01ce7c93a7eafc3ca77b36c76f0d12df1329 Mon Sep 17 00:00:00 2001 From: Pazus Date: Sat, 23 Feb 2019 11:46:53 +0300 Subject: [PATCH 2/2] exclude codestyle from gitignore added dictionaries to VCS --- .gitignore | 6 +++++- .idea/dictionaries/utPLSQL.xml | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .idea/dictionaries/utPLSQL.xml diff --git a/.gitignore b/.gitignore index 58e31d2..3a7808b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # IntelliJ *.iml -.idea/ + +.idea/* +!/.idea/codeStyles +!/.idea/dictionaries # Maven target/ @@ -21,3 +24,4 @@ buildNumber.properties #Exclude CoverageHTMLReporter resources as they are managed by maven src/main/resources/CoverageHTMLReporter/ /gradle.properties + diff --git a/.idea/dictionaries/utPLSQL.xml b/.idea/dictionaries/utPLSQL.xml new file mode 100644 index 0000000..6cb7c83 --- /dev/null +++ b/.idea/dictionaries/utPLSQL.xml @@ -0,0 +1,7 @@ + + + + utplsql + + + \ No newline at end of file