Skip to content

Commit

Permalink
Merge pull request #59 from Pazus/feature/cleanup
Browse files Browse the repository at this point in the history
Cleanup base on IDEA Code Inspector and small refactoring
  • Loading branch information
pesse authored Jul 17, 2018
2 parents 9c7f855 + 141215a commit c007ca9
Show file tree
Hide file tree
Showing 33 changed files with 161 additions and 206 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.utplsql.api;

import oracle.jdbc.OracleTypes;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;

import java.sql.*;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/utplsql/api/EnvironmentVariableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
public class EnvironmentVariableUtil {

private EnvironmentVariableUtil() {}

/**
* Returns the value for a given key from environment (see class description)
*
Expand All @@ -43,4 +45,6 @@ public static String getEnvValue(String key, String defaultValue) {

return val;
}


}
2 changes: 1 addition & 1 deletion src/main/java/org/utplsql/api/FileMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Array buildFileMappingArray(
Connection conn, FileMapperOptions mapperOptions) throws SQLException {
OracleConnection oraConn = conn.unwrap(OracleConnection.class);

Map typeMap = conn.getTypeMap();
Map<String, Class<?>> typeMap = conn.getTypeMap();
typeMap.put(CustomTypes.UT_FILE_MAPPING, FileMapping.class);
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class);
conn.setTypeMap(typeMap);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/org/utplsql/api/FileMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,42 @@ public class FileMapping implements SQLData {

public FileMapping() {}

public FileMapping(String fileName, String objectOwner, String objectName, String objectType) {
this.fileName = fileName;
this.objectOwner = objectOwner;
this.objectName = objectName;
this.objectType = objectType;
}

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
private void setFileName(String fileName) {
this.fileName = fileName;
}

public String getObjectOwner() {
return objectOwner;
}

public void setObjectOwner(String objectOwner) {
private void setObjectOwner(String objectOwner) {
this.objectOwner = objectOwner;
}

public String getObjectName() {
return objectName;
}

public void setObjectName(String objectName) {
private void setObjectName(String objectName) {
this.objectName = objectName;
}

public String getObjectType() {
return objectType;
}

public void setObjectType(String objectType) {
private void setObjectType(String objectType) {
this.objectType = objectType;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
public class JavaApiVersionInfo {

private JavaApiVersionInfo() { }

private static final String BUILD_NO = "123";
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/org/utplsql/api/KeyValuePair.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,30 @@ public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

@Override
public String getSQLTypeName() throws SQLException {
return CustomTypes.UT_KEY_VALUE_PAIR;
}

@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
setKey(stream.readString());
setValue(stream.readString());
key = stream.readString();
value = stream.readString();
}

@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeString(getKey());
stream.writeString(getValue());
stream.writeString(key);
stream.writeString(value);
}

@Override
public String toString() {
return String.format("%s => %s", getKey(), getValue());
return String.format("%s => %s", key, value);
}

}
2 changes: 2 additions & 0 deletions src/main/java/org/utplsql/api/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
public class ResourceUtil {

private ResourceUtil() {}

/**
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
*
Expand Down
23 changes: 6 additions & 17 deletions src/main/java/org/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.utplsql.api;

import oracle.jdbc.OracleConnection;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.SomeTestsFailedException;
Expand All @@ -10,7 +9,6 @@
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.api.testRunner.TestRunnerStatement;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
Expand All @@ -24,18 +22,18 @@
*/
public class TestRunner {

private TestRunnerOptions options = new TestRunnerOptions();
private final TestRunnerOptions options = new TestRunnerOptions();
private CompatibilityProxy compatibilityProxy;
private ReporterFactory reporterFactory;
private List<String> reporterNames = new ArrayList<>();
private final List<String> reporterNames = new ArrayList<>();

public TestRunner addPath(String path) {
options.pathList.add(path);
return this;
}

public TestRunner addPathList(List<String> paths) {
if (options.pathList != null) options.pathList.addAll(paths);
options.pathList.addAll(paths);
return this;
}

Expand Down Expand Up @@ -115,7 +113,7 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) {

private void delayedAddReporters() {
if ( reporterFactory != null )
reporterNames.stream().forEach( this::addReporter );
reporterNames.forEach( this::addReporter );
else
throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!");
}
Expand All @@ -142,13 +140,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
options.reporterList.add(new DocumentationReporter().init(conn));
}

TestRunnerStatement testRunnerStatement = null;

try {
DBHelper.enableDBMSOutput(conn);

testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn);

DBHelper.enableDBMSOutput(conn);
try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) {
testRunnerStatement.execute();
} catch (SQLException e) {
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
Expand All @@ -161,10 +154,6 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
throw e;
}
} finally {
if (testRunnerStatement != null) {
testRunnerStatement.close();
}

DBHelper.disableDBMSOutput(conn);
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/utplsql/api/TestRunnerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.utplsql.api.reporter.Reporter;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -12,14 +11,14 @@
* @author pesse
*/
public class TestRunnerOptions {
public List<String> pathList = new ArrayList<>();
public List<Reporter> reporterList = new ArrayList<>();
public final List<String> pathList = new ArrayList<>();
public final List<Reporter> reporterList = new ArrayList<>();
public boolean colorConsole = false;
public List<String> coverageSchemes = new ArrayList<>();
public List<String> sourceFiles = new ArrayList<>();
public List<String> testFiles = new ArrayList<>();
public List<String> includeObjects = new ArrayList<>();
public List<String> excludeObjects = new ArrayList<>();
public final List<String> coverageSchemes = new ArrayList<>();
public final List<String> sourceFiles = new ArrayList<>();
public final List<String> testFiles = new ArrayList<>();
public final List<String> includeObjects = new ArrayList<>();
public final List<String> excludeObjects = new ArrayList<>();
public FileMapperOptions sourceMappingOptions;
public FileMapperOptions testMappingOptions;
public boolean failOnErrors = false;
Expand Down
68 changes: 32 additions & 36 deletions src/main/java/org/utplsql/api/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,52 @@
* @author pesse
*/
public class Version implements Comparable<Version> {
private String origString;
private Integer major;
private Integer minor;
private Integer bugfix;
private Integer build;
private boolean valid = false;
private final String origString;
private final Integer major;
private final Integer minor;
private final Integer bugfix;
private final Integer build;
private final boolean valid;

public Version( String versionString ) {
assert versionString != null;
this.origString = versionString;
parseVersionString();
}
this.origString = versionString.trim();

private void parseVersionString()
{
Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?");

Matcher m = p.matcher(origString);

Integer major = null;
Integer minor = null;
Integer bugfix = null;
Integer build = null;
boolean valid = false;

try {
if (m.find()) {
if ( m.group(1) != null )
if (m.group(1) != null )
major = Integer.valueOf(m.group(1));
if ( m.group(2) != null )
if (m.group(2) != null )
minor = Integer.valueOf(m.group(2));
if ( m.group(3) != null )
if (m.group(3) != null )
bugfix = Integer.valueOf(m.group(3));
if ( m.group(4) != null )
if (m.group(4) != null )
build = Integer.valueOf(m.group(4));

if ( major != null ) // We need a valid major version as minimum requirement for a Version object to be valid
valid = true;
// We need a valid major version as minimum requirement for a Version object to be valid
valid = major != null;
}
}
catch ( NumberFormatException e )
{
valid = false;
}

this.major = major;
this.minor = minor;
this.bugfix = bugfix;
this.build = build;
this.valid = valid;
}

@Override
Expand Down Expand Up @@ -85,11 +93,11 @@ public String getNormalizedString()
StringBuilder sb = new StringBuilder();
sb.append(String.valueOf(major));
if ( minor != null )
sb.append("." + String.valueOf(minor));
sb.append(".").append(String.valueOf(minor));
if ( bugfix != null )
sb.append("." + String.valueOf(bugfix));
sb.append(".").append(String.valueOf(bugfix));
if ( build != null )
sb.append("." + String.valueOf(build));
sb.append(".").append(String.valueOf(build));

return sb.toString();
}
Expand Down Expand Up @@ -152,41 +160,29 @@ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException

versionsAreValid(v);

if ( compareTo(v) >= 0 )
return true;
else
return false;
return compareTo(v) >= 0;
}


public boolean isGreaterThan( Version v) throws InvalidVersionException
{
versionsAreValid(v);

if ( compareTo(v) > 0 )
return true;
else
return false;
return compareTo(v) > 0;
}

public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException
{

versionsAreValid(v);

if ( compareTo(v) <= 0 )
return true;
else
return false;
return compareTo(v) <= 0;
}

public boolean isLessThan( Version v) throws InvalidVersionException
{
versionsAreValid(v);

if ( compareTo(v) < 0 )
return true;
else
return false;
return compareTo(v) < 0;
}
}
Loading

0 comments on commit c007ca9

Please sign in to comment.