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

Skip to content

Commit 09baf0f

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 9c7f855 commit 09baf0f

37 files changed

Lines changed: 282 additions & 261 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>
@@ -38,13 +37,7 @@
3837
</dependency>
3938
<dependency>
4039
<groupId>org.junit.jupiter</groupId>
41-
<artifactId>junit-jupiter-api</artifactId>
42-
<version>${junit.jupiter.version}</version>
43-
<scope>test</scope>
44-
</dependency>
45-
<dependency>
46-
<groupId>org.junit.jupiter</groupId>
47-
<artifactId>junit-jupiter-engine</artifactId>
40+
<artifactId>junit-jupiter</artifactId>
4841
<version>${junit.jupiter.version}</version>
4942
<scope>test</scope>
5043
</dependency>
@@ -179,25 +172,18 @@
179172
<plugin>
180173
<groupId>org.apache.maven.plugins</groupId>
181174
<artifactId>maven-surefire-plugin</artifactId>
182-
<version>2.19.1</version>
175+
<version>2.22.0</version>
183176
<configuration>
184177
<excludes>
185178
<exclude>**/*IT.java</exclude>
186179
</excludes>
187180
<trimStackTrace>false</trimStackTrace>
188181
</configuration>
189-
<dependencies>
190-
<dependency>
191-
<groupId>org.junit.platform</groupId>
192-
<artifactId>junit-platform-surefire-provider</artifactId>
193-
<version>${junit.platform.version}</version>
194-
</dependency>
195-
</dependencies>
196182
</plugin>
197183
<plugin>
198184
<groupId>org.apache.maven.plugins</groupId>
199185
<artifactId>maven-failsafe-plugin</artifactId>
200-
<version>2.19.1</version>
186+
<version>2.22.0</version>
201187
<executions>
202188
<execution>
203189
<goals>
@@ -206,13 +192,6 @@
206192
</goals>
207193
</execution>
208194
</executions>
209-
<dependencies>
210-
<dependency>
211-
<groupId>org.junit.platform</groupId>
212-
<artifactId>junit-platform-surefire-provider</artifactId>
213-
<version>${junit.platform.version}</version>
214-
</dependency>
215-
</dependencies>
216195
</plugin>
217196
</plugins>
218197
</build>

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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.*;
7+
import java.util.Objects;
88

99
/**
1010
* Database utility functions.
@@ -51,13 +51,13 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
5151
*/
5252
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
5353
assert conn != null;
54-
Version result = new Version("");
54+
Version result = Version.create("");
5555
try (PreparedStatement stmt = conn.prepareStatement("select ut_runner.version() from dual"))
5656
{
5757
ResultSet rs = stmt.executeQuery();
5858

5959
if ( rs.next() )
60-
result = new Version(rs.getString(1));
60+
result = Version.create(rs.getString(1));
6161

6262
rs.close();
6363
} catch ( SQLException e ) {
@@ -115,4 +115,20 @@ public static void disableDBMSOutput(Connection conn) {
115115
System.out.println("Failed to disable dbms_output.");
116116
}
117117
}
118+
119+
public static void withDBMSOutput(Connection conn, SqlCommand task) throws SQLException {
120+
Objects.requireNonNull(conn, "Connection must be provided");
121+
try {
122+
enableDBMSOutput(conn);
123+
task.accept(conn);
124+
}
125+
finally {
126+
disableDBMSOutput(conn);
127+
}
128+
}
129+
130+
@FunctionalInterface
131+
public interface SqlCommand {
132+
void accept(Connection conn) throws SQLException;
133+
}
118134
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
public class JavaApiVersionInfo {
99

10-
private static final String BUILD_NO = "123";
10+
private static final String BUILD_NO = "local";
1111
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
1212
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";
1313

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

Lines changed: 19 additions & 25 deletions
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;
@@ -142,31 +140,27 @@ 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-
152-
testRunnerStatement.execute();
153-
} catch (SQLException e) {
154-
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
155-
throw new SomeTestsFailedException(e.getMessage(), e);
156-
}
157-
else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
158-
throw new UtPLSQLNotInstalledException(e);
159-
}
160-
else {
161-
throw e;
162-
}
163-
} finally {
164-
if (testRunnerStatement != null) {
165-
testRunnerStatement.close();
143+
DBHelper.withDBMSOutput(conn, connection -> {
144+
try {
145+
DBHelper.enableDBMSOutput(conn);
146+
147+
try (TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) {
148+
testRunnerStatement.execute();
149+
}
150+
151+
} catch (SQLException e) {
152+
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
153+
throw new SomeTestsFailedException(e.getMessage(), e);
154+
}
155+
else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
156+
throw new UtPLSQLNotInstalledException(e);
157+
}
158+
else {
159+
throw e;
160+
}
166161
}
162+
});
167163

168-
DBHelper.disableDBMSOutput(conn);
169-
}
170164
}
171165

172166
/**

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

Lines changed: 0 additions & 1 deletion
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

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

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,80 @@
22

33
import org.utplsql.api.exception.InvalidVersionException;
44

5+
import java.util.Map;
6+
import java.util.Objects;
7+
import java.util.function.Function;
58
import java.util.regex.Matcher;
69
import java.util.regex.Pattern;
10+
import java.util.stream.Stream;
11+
12+
import static java.util.stream.Collectors.toMap;
713

814
/** Simple class to parse utPLSQL Version-information and provide the separate version-numbers
915
*
1016
* @author pesse
1117
*/
1218
public class Version implements Comparable<Version> {
13-
private String origString;
14-
private Integer major;
15-
private Integer minor;
16-
private Integer bugfix;
17-
private Integer build;
18-
private boolean valid = false;
19-
20-
public Version( String versionString ) {
19+
20+
public final static Version V3_0_0 = new Version("3.0.0", 3,0,0,null, true);
21+
public final static Version V3_0_1 = new Version("3.0.1", 3,0,1,null, true);
22+
public final static Version V3_0_2 = new Version("3.0.2", 3,0,2,null, true);
23+
public final static Version V3_0_3 = new Version("3.0.3", 3,0,3,null, true);
24+
public final static Version V3_0_4 = new Version("3.0.4", 3,0,4,null, true);
25+
public final static Version V3_1_0 = new Version("3.1.0", 3,1,0,null, true);
26+
public final static Version V3_1_1 = new Version("3.1.1", 3,1,1,null, true);
27+
public final static Version V3_1_2 = new Version("3.1.2", 3,1,2,null, true);
28+
private final static Map<String, Version> knownVersions =
29+
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)
30+
.collect(toMap(Version::toString, Function.identity()));
31+
32+
private final String origString;
33+
private final Integer major;
34+
private final Integer minor;
35+
private final Integer bugfix;
36+
private final Integer build;
37+
private final boolean valid;
38+
39+
private Version(String origString, Integer major, Integer minor, Integer bugfix, Integer build, boolean valid) {
40+
this.origString = origString;
41+
this.major = major;
42+
this.minor = minor;
43+
this.bugfix = bugfix;
44+
this.build = build;
45+
this.valid = valid;
46+
}
47+
48+
/**
49+
* Use {@link Version#create} factory method instead
50+
* For removal
51+
*/
52+
@Deprecated()
53+
public Version(String versionString) {
2154
assert versionString != null;
22-
this.origString = versionString;
23-
parseVersionString();
55+
Version dummy = parseVersionString(versionString);
56+
57+
this.origString = dummy.origString;
58+
this.major = dummy.major;
59+
this.minor =dummy.minor;
60+
this.bugfix = dummy.bugfix;
61+
this.build = dummy.build;
62+
this.valid = dummy.valid;
2463
}
2564

26-
private void parseVersionString()
65+
public static Version create(final String versionString) {
66+
String origString = Objects.requireNonNull(versionString);
67+
Version version = knownVersions.get(origString);
68+
return version != null ? version : parseVersionString(origString);
69+
}
70+
71+
private static Version parseVersionString(String origString)
2772
{
73+
74+
Integer major = null;
75+
Integer minor = null;
76+
Integer bugfix = null;
77+
Integer build = null;
78+
boolean valid = false;
2879
Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?");
2980

3081
Matcher m = p.matcher(origString);
@@ -48,6 +99,8 @@ private void parseVersionString()
4899
{
49100
valid = false;
50101
}
102+
103+
return new Version(origString, major, minor, bugfix, build, valid);
51104
}
52105

53106
@Override
@@ -83,13 +136,13 @@ public String getNormalizedString()
83136
{
84137
if ( isValid() ) {
85138
StringBuilder sb = new StringBuilder();
86-
sb.append(String.valueOf(major));
139+
sb.append(major);
87140
if ( minor != null )
88-
sb.append("." + String.valueOf(minor));
141+
sb.append(".").append(minor);
89142
if ( bugfix != null )
90-
sb.append("." + String.valueOf(bugfix));
143+
sb.append(".").append(bugfix);
91144
if ( build != null )
92-
sb.append("." + String.valueOf(build));
145+
sb.append(".").append(build);
93146

94147
return sb.toString();
95148
}

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

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class CompatibilityProxy {
2626
public static final String UTPLSQL_API_VERSION = "3.1.0";
2727
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";
2828

29-
private Version databaseVersion;
30-
private boolean compatible = false;
29+
private final Version databaseVersion;
30+
private final boolean compatible;
3131

3232
public CompatibilityProxy( Connection conn ) throws SQLException
3333
{
@@ -36,39 +36,26 @@ public CompatibilityProxy( Connection conn ) throws SQLException
3636

3737
public CompatibilityProxy( Connection conn, boolean skipCompatibilityCheck ) throws SQLException
3838
{
39-
if ( skipCompatibilityCheck )
40-
doExpectCompatibility();
41-
else
42-
doCompatibilityCheckWithDatabase(conn);
43-
}
44-
45-
/** Receives the current framework version from database and checks - depending on the framework version - whether
46-
* the API version is compatible or not.
47-
*
48-
* @param conn
49-
* @throws SQLException
50-
*/
51-
private void doCompatibilityCheckWithDatabase( Connection conn ) throws SQLException
52-
{
53-
databaseVersion = DBHelper.getDatabaseFrameworkVersion(conn);
54-
55-
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
56-
try {
57-
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
58-
} catch (SQLException e) {
59-
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), new Version(UTPLSQL_COMPATIBILITY_VERSION), new Version("Unknown"), e);
60-
}
61-
} else
62-
compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
63-
}
64-
65-
/** Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
66-
*
67-
*/
68-
private void doExpectCompatibility()
69-
{
70-
databaseVersion = new Version(UTPLSQL_API_VERSION);
71-
compatible = true;
39+
if ( skipCompatibilityCheck ) {
40+
// Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
41+
databaseVersion = Version.create(UTPLSQL_API_VERSION);
42+
compatible = true;
43+
}
44+
else {
45+
// Receives the current framework version from database and checks - depending on the framework
46+
// version - whether the API version is compatible or not.
47+
databaseVersion = DBHelper.getDatabaseFrameworkVersion(conn);
48+
49+
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
50+
try {
51+
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
52+
} catch (SQLException e) {
53+
throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(),
54+
Version.create(UTPLSQL_COMPATIBILITY_VERSION), Version.create("Unknown"), e);
55+
}
56+
} else
57+
compatible = versionCompatibilityCheckPre303(UTPLSQL_COMPATIBILITY_VERSION);
58+
}
7259
}
7360

7461
/**
@@ -110,7 +97,7 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
11097
*/
11198
private boolean versionCompatibilityCheckPre303( String requested )
11299
{
113-
Version requesteVersion = new Version(requested);
100+
Version requesteVersion = Version.create(requested);
114101

115102
if ( databaseVersion.getMajor() == requesteVersion.getMajor() && (requesteVersion.getMinor() == null || databaseVersion.getMinor() == requesteVersion.getMinor()) )
116103
return true;

0 commit comments

Comments
 (0)