Skip to content

Commit 5c6f000

Browse files
committed
Trivial cleanup (remove unnecessary imports, making properties final, simplified if statements etc) based on IDEA code inspector
Refactored creation of ReporterInspectors. Made them immutable, separated creation from ReporterInfo collection fill Made TestRunnerStatement AutoClosable to be used with try-with-resource For SQLData implementations (FileMapping, KeyValuePair) made setters private
1 parent 9c7f855 commit 5c6f000

22 files changed

+101
-143
lines changed

Diff for: src/main/java/org/utplsql/api/DBHelper.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utplsql.api;
22

33
import oracle.jdbc.OracleTypes;
4-
import org.utplsql.api.exception.DatabaseNotCompatibleException;
54
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
65

76
import java.sql.*;

Diff for: src/main/java/org/utplsql/api/FileMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static Array buildFileMappingArray(
2020
Connection conn, FileMapperOptions mapperOptions) throws SQLException {
2121
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
2222

23-
Map typeMap = conn.getTypeMap();
23+
Map<String, Class<?>> typeMap = conn.getTypeMap();
2424
typeMap.put(CustomTypes.UT_FILE_MAPPING, FileMapping.class);
2525
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class);
2626
conn.setTypeMap(typeMap);

Diff for: src/main/java/org/utplsql/api/FileMapping.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,42 @@ public class FileMapping implements SQLData {
1717

1818
public FileMapping() {}
1919

20+
public FileMapping(String fileName, String objectOwner, String objectName, String objectType) {
21+
this.fileName = fileName;
22+
this.objectOwner = objectOwner;
23+
this.objectName = objectName;
24+
this.objectType = objectType;
25+
}
26+
2027
public String getFileName() {
2128
return fileName;
2229
}
2330

24-
public void setFileName(String fileName) {
31+
private void setFileName(String fileName) {
2532
this.fileName = fileName;
2633
}
2734

2835
public String getObjectOwner() {
2936
return objectOwner;
3037
}
3138

32-
public void setObjectOwner(String objectOwner) {
39+
private void setObjectOwner(String objectOwner) {
3340
this.objectOwner = objectOwner;
3441
}
3542

3643
public String getObjectName() {
3744
return objectName;
3845
}
3946

40-
public void setObjectName(String objectName) {
47+
private void setObjectName(String objectName) {
4148
this.objectName = objectName;
4249
}
4350

4451
public String getObjectType() {
4552
return objectType;
4653
}
4754

48-
public void setObjectType(String objectType) {
55+
private void setObjectType(String objectType) {
4956
this.objectType = objectType;
5057
}
5158

Diff for: src/main/java/org/utplsql/api/KeyValuePair.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,30 @@ public String getKey() {
2222
return key;
2323
}
2424

25-
public void setKey(String key) {
26-
this.key = key;
27-
}
28-
2925
public String getValue() {
3026
return value;
3127
}
3228

33-
public void setValue(String value) {
34-
this.value = value;
35-
}
36-
3729
@Override
3830
public String getSQLTypeName() throws SQLException {
3931
return CustomTypes.UT_KEY_VALUE_PAIR;
4032
}
4133

4234
@Override
4335
public void readSQL(SQLInput stream, String typeName) throws SQLException {
44-
setKey(stream.readString());
45-
setValue(stream.readString());
36+
key = stream.readString();
37+
value = stream.readString();
4638
}
4739

4840
@Override
4941
public void writeSQL(SQLOutput stream) throws SQLException {
50-
stream.writeString(getKey());
51-
stream.writeString(getValue());
42+
stream.writeString(key);
43+
stream.writeString(value);
5244
}
5345

5446
@Override
5547
public String toString() {
56-
return String.format("%s => %s", getKey(), getValue());
48+
return String.format("%s => %s", key, value);
5749
}
5850

5951
}

Diff for: src/main/java/org/utplsql/api/TestRunner.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utplsql.api;
22

3-
import oracle.jdbc.OracleConnection;
43
import org.utplsql.api.compatibility.CompatibilityProxy;
54
import org.utplsql.api.exception.DatabaseNotCompatibleException;
65
import org.utplsql.api.exception.SomeTestsFailedException;
@@ -10,7 +9,6 @@
109
import org.utplsql.api.reporter.ReporterFactory;
1110
import org.utplsql.api.testRunner.TestRunnerStatement;
1211

13-
import java.sql.CallableStatement;
1412
import java.sql.Connection;
1513
import java.sql.SQLException;
1614
import java.util.ArrayList;
@@ -24,18 +22,18 @@
2422
*/
2523
public class TestRunner {
2624

27-
private TestRunnerOptions options = new TestRunnerOptions();
25+
private final TestRunnerOptions options = new TestRunnerOptions();
2826
private CompatibilityProxy compatibilityProxy;
2927
private ReporterFactory reporterFactory;
30-
private List<String> reporterNames = new ArrayList<>();
28+
private final List<String> reporterNames = new ArrayList<>();
3129

3230
public TestRunner addPath(String path) {
3331
options.pathList.add(path);
3432
return this;
3533
}
3634

3735
public TestRunner addPathList(List<String> paths) {
38-
if (options.pathList != null) options.pathList.addAll(paths);
36+
options.pathList.addAll(paths);
3937
return this;
4038
}
4139

@@ -115,7 +113,7 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) {
115113

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

145-
TestRunnerStatement testRunnerStatement = null;
146-
147-
try {
148-
DBHelper.enableDBMSOutput(conn);
149-
150-
testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn);
151-
143+
DBHelper.enableDBMSOutput(conn);
144+
try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) {
152145
testRunnerStatement.execute();
153146
} catch (SQLException e) {
154147
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
@@ -161,10 +154,6 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
161154
throw e;
162155
}
163156
} finally {
164-
if (testRunnerStatement != null) {
165-
testRunnerStatement.close();
166-
}
167-
168157
DBHelper.disableDBMSOutput(conn);
169158
}
170159
}

Diff for: src/main/java/org/utplsql/api/TestRunnerOptions.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.utplsql.api.reporter.Reporter;
44

55
import java.nio.charset.Charset;
6-
import java.nio.charset.StandardCharsets;
76
import java.util.ArrayList;
87
import java.util.List;
98

@@ -12,14 +11,14 @@
1211
* @author pesse
1312
*/
1413
public class TestRunnerOptions {
15-
public List<String> pathList = new ArrayList<>();
16-
public List<Reporter> reporterList = new ArrayList<>();
14+
public final List<String> pathList = new ArrayList<>();
15+
public final List<Reporter> reporterList = new ArrayList<>();
1716
public boolean colorConsole = false;
18-
public List<String> coverageSchemes = new ArrayList<>();
19-
public List<String> sourceFiles = new ArrayList<>();
20-
public List<String> testFiles = new ArrayList<>();
21-
public List<String> includeObjects = new ArrayList<>();
22-
public List<String> excludeObjects = new ArrayList<>();
17+
public final List<String> coverageSchemes = new ArrayList<>();
18+
public final List<String> sourceFiles = new ArrayList<>();
19+
public final List<String> testFiles = new ArrayList<>();
20+
public final List<String> includeObjects = new ArrayList<>();
21+
public final List<String> excludeObjects = new ArrayList<>();
2322
public FileMapperOptions sourceMappingOptions;
2423
public FileMapperOptions testMappingOptions;
2524
public boolean failOnErrors = false;

Diff for: src/main/java/org/utplsql/api/Version.java

+7-19
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public String getNormalizedString()
8585
StringBuilder sb = new StringBuilder();
8686
sb.append(String.valueOf(major));
8787
if ( minor != null )
88-
sb.append("." + String.valueOf(minor));
88+
sb.append(".").append(String.valueOf(minor));
8989
if ( bugfix != null )
90-
sb.append("." + String.valueOf(bugfix));
90+
sb.append(".").append(String.valueOf(bugfix));
9191
if ( build != null )
92-
sb.append("." + String.valueOf(build));
92+
sb.append(".").append(String.valueOf(build));
9393

9494
return sb.toString();
9595
}
@@ -152,41 +152,29 @@ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException
152152

153153
versionsAreValid(v);
154154

155-
if ( compareTo(v) >= 0 )
156-
return true;
157-
else
158-
return false;
155+
return compareTo(v) >= 0;
159156
}
160157

161158

162159
public boolean isGreaterThan( Version v) throws InvalidVersionException
163160
{
164161
versionsAreValid(v);
165162

166-
if ( compareTo(v) > 0 )
167-
return true;
168-
else
169-
return false;
163+
return compareTo(v) > 0;
170164
}
171165

172166
public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException
173167
{
174168

175169
versionsAreValid(v);
176170

177-
if ( compareTo(v) <= 0 )
178-
return true;
179-
else
180-
return false;
171+
return compareTo(v) <= 0;
181172
}
182173

183174
public boolean isLessThan( Version v) throws InvalidVersionException
184175
{
185176
versionsAreValid(v);
186177

187-
if ( compareTo(v) < 0 )
188-
return true;
189-
else
190-
return false;
178+
return compareTo(v) < 0;
191179
}
192180
}

Diff for: src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ private void doExpectCompatibility()
7979
*/
8080
private boolean versionCompatibilityCheck(Connection conn, String requested, String current)
8181
throws SQLException {
82-
CallableStatement callableStatement = null;
83-
try {
84-
callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;");
82+
try(CallableStatement callableStatement = conn.prepareCall("BEGIN ? := ut_runner.version_compatibility_check(?, ?); END;")) {
8583
callableStatement.registerOutParameter(1, Types.SMALLINT);
8684
callableStatement.setString(2, requested);
8785

@@ -97,9 +95,6 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
9795
return false;
9896
else
9997
throw e;
100-
} finally {
101-
if (callableStatement != null)
102-
callableStatement.close();
10398
}
10499
}
105100

@@ -108,11 +103,11 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
108103
* @param requested
109104
* @return
110105
*/
111-
private boolean versionCompatibilityCheckPre303( String requested )
106+
private boolean versionCompatibilityCheckPre303(String requested )
112107
{
113108
Version requesteVersion = new Version(requested);
114109

115-
if ( databaseVersion.getMajor() == requesteVersion.getMajor() && (requesteVersion.getMinor() == null || databaseVersion.getMinor() == requesteVersion.getMinor()) )
110+
if (databaseVersion.getMajor().equals(requesteVersion.getMajor()) && (requesteVersion.getMinor() == null || requesteVersion.getMinor().equals(databaseVersion.getMinor())) )
116111
return true;
117112
else
118113
return false;

Diff for: src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ public enum OptionalFeatures {
2626
public boolean isAvailableFor(Version version ) {
2727

2828
try {
29-
if ((minVersion == null || version.isGreaterOrEqualThan(minVersion)) &&
30-
(maxVersion == null || maxVersion.isGreaterOrEqualThan(version))
31-
)
32-
return true;
33-
else
34-
return false;
29+
return (minVersion == null || version.isGreaterOrEqualThan(minVersion)) &&
30+
(maxVersion == null || maxVersion.isGreaterOrEqualThan(version));
3531
} catch ( InvalidVersionException e ) {
3632
return false; // We have no optional features for invalid versions
3733
}

Diff for: src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utplsql.api.exception;
22

3-
import org.utplsql.api.DBHelper;
43
import org.utplsql.api.Version;
54
import org.utplsql.api.compatibility.CompatibilityProxy;
65

@@ -13,8 +12,8 @@
1312
*/
1413
public class DatabaseNotCompatibleException extends SQLException {
1514

16-
private Version clientVersion;
17-
private Version databaseVersion;
15+
private final Version clientVersion;
16+
private final Version databaseVersion;
1817

1918
public DatabaseNotCompatibleException( String message, Version clientVersion, Version databaseVersion, Throwable cause )
2019
{

Diff for: src/main/java/org/utplsql/api/exception/InvalidVersionException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author pesse
88
*/
99
public class InvalidVersionException extends Exception {
10-
private Version version;
10+
private final Version version;
1111

1212
public InvalidVersionException( Version version ) {
1313
this( version, null );

Diff for: src/main/java/org/utplsql/api/outputBuffer/NonOutputBuffer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class NonOutputBuffer implements OutputBuffer {
1717

18-
private Reporter reporter;
18+
private final Reporter reporter;
1919

2020
NonOutputBuffer( Reporter reporter) {
2121
this.reporter = reporter;

Diff for: src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
3434
}
3535
}
3636
}
37-
catch ( InvalidVersionException e ) { }
37+
catch ( InvalidVersionException ignored ) { }
3838

3939
// If we couldn't find an appropriate OutputBuffer, return the Pre310-Compatibility-Buffer
4040
return new CompatibilityOutputBufferPre310(reporter);
@@ -52,10 +52,8 @@ private static boolean hasOutput( Reporter reporter, OracleConnection oraConn )
5252

5353
if ( isReporterResult == null )
5454
throw new IllegalArgumentException("The given type " + reporter.getTypeName() + " is not a valid Reporter!");
55-
else if (isReporterResult.equalsIgnoreCase("Y") )
56-
return true;
5755
else
58-
return false;
56+
return isReporterResult.equalsIgnoreCase("Y");
5957
}
6058
else
6159
throw new SQLException("Could not check Reporter validity");

Diff for: src/main/java/org/utplsql/api/reporter/CoreReporters.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public enum CoreReporters {
1919
UT_SONAR_TEST_REPORTER(new Version("3.0.0"), null),
2020
UT_COVERAGE_COBERTURA_REPORTER(new Version("3.1.0"), null);
2121

22-
private Version since;
23-
private Version until;
22+
private final Version since;
23+
private final Version until;
2424

2525
CoreReporters(Version since, Version until ) {
2626
this.since = since;
@@ -46,7 +46,7 @@ public boolean isAvailableFor( Version databaseVersion ) {
4646
&& (until == null || databaseVersion.isLessOrEqualThan(until)))
4747
return true;
4848
}
49-
catch ( InvalidVersionException e ) { }
49+
catch ( InvalidVersionException ignored ) { }
5050

5151
return false;
5252
}

0 commit comments

Comments
 (0)