Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fbee99

Browse files
committed
updated jUnit to 5.4 version
made all possible properties final, others need additional refactoring narrowed availability of test methods down to package-private as public is not needed nor recommended for jUnit 5 tests
1 parent 76ba799 commit 9fbee99

27 files changed

Lines changed: 214 additions & 205 deletions

pom.xml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<maven.compiler.source>1.8</maven.compiler.source>
1616
<maven.compiler.target>1.8</maven.compiler.target>
17-
<junit.platform.version>1.0.3</junit.platform.version>
18-
<junit.jupiter.version>5.0.3</junit.jupiter.version>
17+
<junit.jupiter.version>5.4.0</junit.jupiter.version>
1918
<coverage.resources.directory>${basedir}/src/main/resources/CoverageHTMLReporter</coverage.resources.directory>
2019
<coverage.resources.version>1.0.1</coverage.resources.version>
2120
<coverage.resources.zip.directory>utPLSQL-coverage-html-${coverage.resources.version}</coverage.resources.zip.directory>
@@ -50,13 +49,7 @@
5049
<!-- Tests -->
5150
<dependency>
5251
<groupId>org.junit.jupiter</groupId>
53-
<artifactId>junit-jupiter-api</artifactId>
54-
<version>${junit.jupiter.version}</version>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.junit.jupiter</groupId>
59-
<artifactId>junit-jupiter-engine</artifactId>
52+
<artifactId>junit-jupiter</artifactId>
6053
<version>${junit.jupiter.version}</version>
6154
<scope>test</scope>
6255
</dependency>
@@ -163,25 +156,18 @@
163156
<plugin>
164157
<groupId>org.apache.maven.plugins</groupId>
165158
<artifactId>maven-surefire-plugin</artifactId>
166-
<version>2.19.1</version>
159+
<version>2.22.0</version>
167160
<configuration>
168161
<excludes>
169162
<exclude>**/*IT.java</exclude>
170163
</excludes>
171164
<trimStackTrace>false</trimStackTrace>
172165
</configuration>
173-
<dependencies>
174-
<dependency>
175-
<groupId>org.junit.platform</groupId>
176-
<artifactId>junit-platform-surefire-provider</artifactId>
177-
<version>${junit.platform.version}</version>
178-
</dependency>
179-
</dependencies>
180166
</plugin>
181167
<plugin>
182168
<groupId>org.apache.maven.plugins</groupId>
183169
<artifactId>maven-failsafe-plugin</artifactId>
184-
<version>2.19.1</version>
170+
<version>2.22.0</version>
185171
<executions>
186172
<execution>
187173
<goals>
@@ -190,13 +176,6 @@
190176
</goals>
191177
</execution>
192178
</executions>
193-
<dependencies>
194-
<dependency>
195-
<groupId>org.junit.platform</groupId>
196-
<artifactId>junit-platform-surefire-provider</artifactId>
197-
<version>${junit.platform.version}</version>
198-
</dependency>
199-
</dependencies>
200179
</plugin>
201180
</plugins>
202181
<resources>

src/main/java/org/utplsql/api/DBHelper.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.utplsql.api;
22

33
import oracle.jdbc.OracleTypes;
4-
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
4+
import org.utplsql.api.db.DatabaseInformation;
5+
import org.utplsql.api.db.DefaultDatabaseInformation;
56

6-
import java.sql.*;
7-
import java.util.Objects;
7+
import java.sql.CallableStatement;
8+
import java.sql.Connection;
9+
import java.sql.SQLException;
10+
import java.sql.Types;
811

912
/**
1013
* Database utility functions.
@@ -53,23 +56,9 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
5356
*/
5457
@Deprecated
5558
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
56-
Version result = new Version("");
57-
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
58-
{
59-
ResultSet rs = stmt.executeQuery();
59+
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
60+
return databaseInformation.getUtPlsqlFrameworkVersion(conn);
6061

61-
if ( rs.next() )
62-
result = new Version(rs.getString(1));
63-
64-
rs.close();
65-
} catch ( SQLException e ) {
66-
if ( e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE )
67-
throw new UtPLSQLNotInstalledException(e);
68-
else
69-
throw e;
70-
}
71-
72-
return result;
7362
}
7463

7564
/** Returns the Oracle database Version from a given connection object
@@ -81,16 +70,8 @@ public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLE
8170
*/
8271
@Deprecated
8372
public static String getOracleDatabaseVersion( Connection conn ) throws SQLException {
84-
String result = null;
85-
try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'"))
86-
{
87-
ResultSet rs = stmt.executeQuery();
88-
89-
if ( rs.next() )
90-
result = rs.getString(1);
91-
}
92-
93-
return result;
73+
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
74+
return databaseInformation.getOracleVersion(conn);
9475
}
9576

9677
/**

src/main/java/org/utplsql/api/Version.java

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,83 @@
33
import org.utplsql.api.exception.InvalidVersionException;
44

55
import javax.annotation.Nullable;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
import java.util.function.Function;
69
import java.util.regex.Matcher;
710
import java.util.regex.Pattern;
11+
import java.util.stream.Stream;
12+
13+
import static java.util.stream.Collectors.toMap;
814

915
/** Simple class to parse utPLSQL Version-information and provide the separate version-numbers
1016
*
1117
* @author pesse
1218
*/
1319
public class Version implements Comparable<Version> {
20+
21+
public final static Version V3_0_0 = new Version("3.0.0", 3,0,0,null, true);
22+
public final static Version V3_0_1 = new Version("3.0.1", 3,0,1,null, true);
23+
public final static Version V3_0_2 = new Version("3.0.2", 3,0,2,null, true);
24+
public final static Version V3_0_3 = new Version("3.0.3", 3,0,3,null, true);
25+
public final static Version V3_0_4 = new Version("3.0.4", 3,0,4,null, true);
26+
public final static Version V3_1_0 = new Version("3.1.0", 3,1,0,null, true);
27+
public final static Version V3_1_1 = new Version("3.1.1", 3,1,1,null, true);
28+
public final static Version V3_1_2 = new Version("3.1.2", 3,1,2,null, true);
29+
private final static Map<String, Version> knownVersions =
30+
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)
31+
.collect(toMap(Version::toString, Function.identity()));
32+
1433
private final String origString;
1534
private final Integer major;
1635
private final Integer minor;
1736
private final Integer bugfix;
1837
private final Integer build;
1938
private final boolean valid;
2039

21-
public Version( String versionString ) {
40+
private Version(String origString, Integer major, Integer minor, Integer bugfix, Integer build, boolean valid) {
41+
this.origString = origString;
42+
this.major = major;
43+
this.minor = minor;
44+
this.bugfix = bugfix;
45+
this.build = build;
46+
this.valid = valid;
47+
}
48+
49+
/**
50+
* Use {@link Version#create} factory method instead
51+
* For removal
52+
*/
53+
@Deprecated()
54+
public Version(String versionString) {
2255
assert versionString != null;
23-
this.origString = versionString.trim();
56+
Version dummy = parseVersionString(versionString);
57+
58+
this.origString = dummy.origString;
59+
this.major = dummy.major;
60+
this.minor =dummy.minor;
61+
this.bugfix = dummy.bugfix;
62+
this.build = dummy.build;
63+
this.valid = dummy.valid;
64+
}
2465

25-
Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?");
66+
public static Version create(final String versionString) {
67+
String origString = Objects.requireNonNull(versionString);
68+
Version version = knownVersions.get(origString);
69+
return version != null ? version : parseVersionString(origString);
70+
}
2671

27-
Matcher m = p.matcher(origString);
72+
private static Version parseVersionString(String origString)
73+
{
2874

2975
Integer major = null;
3076
Integer minor = null;
3177
Integer bugfix = null;
3278
Integer build = null;
3379
boolean valid = false;
80+
Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?");
81+
82+
Matcher m = p.matcher(origString);
3483

3584
try {
3685
if (m.find()) {
@@ -52,11 +101,7 @@ public Version( String versionString ) {
52101
valid = false;
53102
}
54103

55-
this.major = major;
56-
this.minor = minor;
57-
this.bugfix = bugfix;
58-
this.build = build;
59-
this.valid = valid;
104+
return new Version(origString, major, minor, bugfix, build, valid);
60105
}
61106

62107
@Override
@@ -92,13 +137,13 @@ public String getNormalizedString()
92137
{
93138
if ( isValid() ) {
94139
StringBuilder sb = new StringBuilder();
95-
sb.append(String.valueOf(major));
140+
sb.append(major);
96141
if ( minor != null )
97-
sb.append(".").append(String.valueOf(minor));
142+
sb.append(".").append(minor);
98143
if ( bugfix != null )
99-
sb.append(".").append(String.valueOf(bugfix));
144+
sb.append(".").append(bugfix);
100145
if ( build != null )
101-
sb.append(".").append(String.valueOf(build));
146+
sb.append(".").append(build);
102147

103148
return sb.toString();
104149
}

src/main/java/org/utplsql/api/compatibility/CompatibilityProxy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck, Data
6262
private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException
6363
{
6464
databaseVersion = databaseInformation.getUtPlsqlFrameworkVersion(conn);
65-
Version clientVersion = new Version(UTPLSQL_COMPATIBILITY_VERSION);
65+
Version clientVersion = Version.create(UTPLSQL_COMPATIBILITY_VERSION);
6666

6767
if ( databaseVersion == null )
6868
throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null);
@@ -74,7 +74,7 @@ private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLExcep
7474
try {
7575
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
7676
} catch (SQLException e) {
77-
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), clientVersion, new Version("Unknown"), e);
77+
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), clientVersion, Version.create("Unknown"), e);
7878
}
7979
} else
8080
compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
@@ -85,7 +85,7 @@ private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLExcep
8585
*/
8686
private void doExpectCompatibility()
8787
{
88-
databaseVersion = new Version(UTPLSQL_API_VERSION);
88+
databaseVersion = Version.create(UTPLSQL_API_VERSION);
8989
compatible = true;
9090
}
9191

@@ -114,7 +114,7 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
114114
*/
115115
private boolean versionCompatibilityCheckPre303(String requested )
116116
{
117-
Version requestedVersion = new Version(requested);
117+
Version requestedVersion = Version.create(requested);
118118

119119
Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString());
120120
return databaseVersion.getMajor().equals(requestedVersion.getMajor())

src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public enum OptionalFeatures {
1717

1818
OptionalFeatures( String minVersion, String maxVersion )
1919
{
20-
this.minVersion = minVersion != null ? new Version(minVersion) : null;
21-
this.maxVersion = maxVersion != null ? new Version(maxVersion) : null;
20+
this.minVersion = minVersion != null ? Version.create(minVersion) : null;
21+
this.maxVersion = maxVersion != null ? Version.create(maxVersion) : null;
2222
}
2323

2424
public boolean isAvailableFor(Version version ) {

src/main/java/org/utplsql/api/db/DefaultDatabaseInformation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55

66
import javax.annotation.Nullable;
77
import java.sql.*;
8-
import java.util.Objects;
98

109
public class DefaultDatabaseInformation implements DatabaseInformation {
1110

1211
@Override
1312
public Version getUtPlsqlFrameworkVersion(Connection conn) throws SQLException {
14-
Version result = new Version("");
13+
Version result = Version.create("");
1514
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
1615
{
1716
ResultSet rs = stmt.executeQuery();
1817

1918
if ( rs.next() )
20-
result = new Version(rs.getString(1));
19+
result = Version.create(rs.getString(1));
2120

2221
rs.close();
2322
} catch ( SQLException e ) {

src/main/java/org/utplsql/api/exception/DatabaseNotCompatibleException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public DatabaseNotCompatibleException( Version clientVersion, Version databaseVe
3535

3636
public DatabaseNotCompatibleException( Version databaseVersion, Throwable cause )
3737
{
38-
this(new Version(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause );
38+
this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause );
3939
}
4040

4141
public DatabaseNotCompatibleException( Version databaseVersion )
4242
{
43-
this(new Version(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null );
43+
this(Version.create(CompatibilityProxy.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null );
4444
}
4545

4646
public Version getClientVersion() {

src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static OutputBuffer getCompatibleOutputBuffer(Version databaseVersion, Re
2525
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
2626

2727
try {
28-
if (databaseVersion.isGreaterOrEqualThan(new Version("3.1.0"))) {
28+
if (databaseVersion.isGreaterOrEqualThan(Version.V3_1_0)) {
2929
if ( hasOutput(reporter, oraConn) ) {
3030
return new DefaultOutputBuffer(reporter);
3131
}

src/main/java/org/utplsql/api/reporter/CoreReporters.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111
public enum CoreReporters {
1212

13-
UT_COVERAGE_HTML_REPORTER(new Version("3.0.0"), null),
14-
UT_DOCUMENTATION_REPORTER(new Version("3.0.0"), null),
15-
UT_TEAMCITY_REPORTER(new Version("3.0.0"), null),
16-
UT_XUNIT_REPORTER(new Version("3.0.0"), null),
17-
UT_COVERALLS_REPORTER(new Version("3.0.0"), null),
18-
UT_COVERAGE_SONAR_REPORTER(new Version("3.0.0"), null),
19-
UT_SONAR_TEST_REPORTER(new Version("3.0.0"), null),
20-
UT_COVERAGE_COBERTURA_REPORTER(new Version("3.1.0"), null);
13+
UT_COVERAGE_HTML_REPORTER(Version.V3_0_0, null),
14+
UT_DOCUMENTATION_REPORTER(Version.V3_0_0, null),
15+
UT_TEAMCITY_REPORTER(Version.V3_0_0, null),
16+
UT_XUNIT_REPORTER(Version.V3_0_0, null),
17+
UT_COVERALLS_REPORTER(Version.V3_0_0, null),
18+
UT_COVERAGE_SONAR_REPORTER(Version.V3_0_0, null),
19+
UT_SONAR_TEST_REPORTER(Version.V3_0_0, null),
20+
UT_COVERAGE_COBERTURA_REPORTER(Version.V3_1_0, null);
2121

2222
private final Version since;
2323
private final Version until;

src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.net.URISyntaxException;
8-
import java.nio.file.*;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.nio.file.StandardCopyOption;
912
import java.util.List;
1013
import java.util.function.Consumer;
1114

0 commit comments

Comments
 (0)