Skip to content

Commit b3c635c

Browse files
committed
Refactor tests to work with JUnit 5
1 parent c699c5f commit b3c635c

File tree

9 files changed

+126
-115
lines changed

9 files changed

+126
-115
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package org.utplsql.api;
22

3-
import org.junit.Assert;
4-
import org.junit.Before;
53
import org.junit.Rule;
6-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
75
import org.utplsql.api.compatibility.CompatibilityProxy;
86
import org.utplsql.api.rules.DatabaseRule;
97

108
import java.sql.Connection;
119
import java.sql.SQLException;
1210

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
1314
public class CompatibilityIT {
1415

1516
@Rule
@@ -21,10 +22,9 @@ public void compatibleVersion() {
2122
Connection conn = db.newConnection();
2223
CompatibilityProxy proxy = new CompatibilityProxy(conn);
2324
proxy.failOnNotCompatible();
24-
Assert.assertEquals(true, proxy.isCompatible());
25+
assertEquals(true, proxy.isCompatible());
2526
} catch (SQLException e) {
26-
e.printStackTrace();
27-
Assert.fail();
27+
fail(e);
2828
}
2929
}
3030

@@ -35,11 +35,10 @@ public void skipCompatibilityCheck()
3535
Connection conn = db.newConnection();
3636
CompatibilityProxy proxy = new CompatibilityProxy(conn, true);
3737
proxy.failOnNotCompatible();
38-
Assert.assertEquals(true, proxy.isCompatible());
39-
Assert.assertEquals(CompatibilityProxy.UTPLSQL_API_VERSION, proxy.getDatabaseVersion().toString());
38+
assertEquals(true, proxy.isCompatible());
39+
assertEquals(CompatibilityProxy.UTPLSQL_API_VERSION, proxy.getDatabaseVersion().toString());
4040
} catch (SQLException e) {
41-
e.printStackTrace();
42-
Assert.fail();
41+
fail(e);
4342
}
4443
}
4544
}

src/test/java/org/utplsql/api/DBHelperIT.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.utplsql.api;
22

3-
import org.junit.Assert;
43
import org.junit.Rule;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
65
import org.utplsql.api.rules.DatabaseRule;
76

87
import java.sql.SQLException;
98

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.fail;
11+
1012
public class DBHelperIT {
1113

1214
@Rule
@@ -17,11 +19,10 @@ public void getFrameworkVersion()
1719
{
1820
try {
1921
Version v = DBHelper.getDatabaseFrameworkVersion(db.newConnection());
20-
Assert.assertEquals(true, v.isValid());
22+
assertEquals(true, v.isValid());
2123
} catch (SQLException e)
2224
{
23-
e.printStackTrace();
24-
Assert.fail();
25+
fail(e);
2526
}
2627
}
2728

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.utplsql.api;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
54

65
import java.util.Map;
76
import java.util.Optional;
87
import java.util.Set;
98

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.fail;
11+
1012

1113
public class EnvironmentVariableUtilTest {
1214

@@ -19,22 +21,22 @@ public void testGetVariableFromEnvironment() {
1921
.findFirst();
2022

2123
if ( !envVariable.isPresent() )
22-
Assert.fail("Can't test for there is no environment variable not overridden by property");
24+
fail ("Can't test for there is no environment variable not overridden by property");
2325

24-
Assert.assertEquals(envVariable.get().getValue(), EnvironmentVariableUtil.getEnvValue(envVariable.get().getKey()));
26+
assertEquals(envVariable.get().getValue(), EnvironmentVariableUtil.getEnvValue(envVariable.get().getKey()));
2527
}
2628

2729
@Test
2830
public void testGetVariableFromProperty() {
2931
System.setProperty("PATH", "MyPath");
3032

31-
Assert.assertEquals("MyPath", EnvironmentVariableUtil.getEnvValue("PATH"));
33+
assertEquals("MyPath", EnvironmentVariableUtil.getEnvValue("PATH"));
3234
}
3335

3436
@Test
3537
public void testGetVariableFromDefault() {
3638

37-
Assert.assertEquals("defaultValue", EnvironmentVariableUtil.getEnvValue("RANDOM"+String.valueOf(System.currentTimeMillis()), "defaultValue"));
39+
assertEquals("defaultValue", EnvironmentVariableUtil.getEnvValue("RANDOM"+String.valueOf(System.currentTimeMillis()), "defaultValue"));
3840
}
3941

4042
}

src/test/java/org/utplsql/api/FileMapperIT.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package org.utplsql.api;
22

3+
import org.junit.jupiter.api.Test;
34
import org.utplsql.api.rules.DatabaseRule;
4-
import org.junit.Assert;
55
import org.junit.Rule;
6-
import org.junit.Test;
76

87
import java.sql.SQLException;
98
import java.util.ArrayList;
109
import java.util.List;
1110

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
1214
public class FileMapperIT {
1315

1416
@Rule
@@ -35,16 +37,16 @@ public void testFileMapper() throws SQLException {
3537
List<FileMapping> fileMappings = FileMapper.buildFileMappingList(db.newConnection(), mapperOptions);
3638

3739
if (fileMappings.size() != 2)
38-
Assert.fail("Wrong mapping list size.");
40+
fail("Wrong mapping list size.");
3941

4042
assertMapping(fileMappings.get(0), "APP", "AWARD_BONUS", "PROCEDURE");
4143
assertMapping(fileMappings.get(1), "APP", "BETWNSTR", "FUNCTION");
4244
}
4345

4446
private void assertMapping(FileMapping fileMapping, String owner, String name, String type) {
45-
Assert.assertEquals(owner, fileMapping.getObjectOwner());
46-
Assert.assertEquals(name, fileMapping.getObjectName());
47-
Assert.assertEquals(type, fileMapping.getObjectType());
47+
assertEquals(owner, fileMapping.getObjectOwner());
48+
assertEquals(name, fileMapping.getObjectName());
49+
assertEquals(type, fileMapping.getObjectType());
4850
}
4951

5052
}

src/test/java/org/utplsql/api/OutputBufferIT.java

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

3+
import org.junit.jupiter.api.Test;
34
import org.utplsql.api.reporter.DocumentationReporter;
45
import org.utplsql.api.reporter.Reporter;
56
import org.utplsql.api.rules.DatabaseRule;
6-
import org.junit.Assert;
77
import org.junit.Rule;
8-
import org.junit.Test;
98

109
import java.io.File;
1110
import java.io.FileOutputStream;
@@ -16,6 +15,9 @@
1615
import java.util.List;
1716
import java.util.concurrent.*;
1817

18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.fail;
20+
1921
/**
2022
* Created by Vinicius on 13/04/2017.
2123
*/
@@ -84,12 +86,12 @@ public void printAvailableLines() {
8486
Object res2 = task2.get();
8587

8688
if (res1 instanceof Exception)
87-
Assert.fail(((Exception) res1).getMessage());
89+
fail((Exception) res1);
8890

8991
if (res2 instanceof Exception)
90-
Assert.fail(((Exception) res2).getMessage());
92+
fail((Exception) res2);
9193
} catch (SQLException e) {
92-
Assert.fail(e.getMessage());
94+
fail(e.getMessage());
9395
} catch (InterruptedException | ExecutionException e) {
9496
e.printStackTrace();
9597
}
@@ -108,9 +110,9 @@ public void fetchAllLines() {
108110
List<String> outputLines = new OutputBuffer(reporter)
109111
.fetchAll(conn);
110112

111-
Assert.assertTrue(outputLines.size() > 0);
113+
assertTrue(outputLines.size() > 0);
112114
} catch (SQLException e) {
113-
Assert.fail(e.getMessage());
115+
fail(e);
114116
}
115117
}
116118

src/test/java/org/utplsql/api/ReporterNameTest.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
package org.utplsql.api;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
54
import org.utplsql.api.reporter.*;
65

76
import java.sql.SQLException;
87

8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
911
public class ReporterNameTest {
1012

1113
@Test
1214
public void reporterSQLTypeName() throws SQLException {
13-
Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, new CoverageHTMLReporter().getSQLTypeName());
14-
Assert.assertEquals(CustomTypes.UT_COVERAGE_SONAR_REPORTER, new CoverageSonarReporter().getSQLTypeName());
15-
Assert.assertEquals(CustomTypes.UT_COVERALLS_REPORTER, new CoverallsReporter().getSQLTypeName());
16-
Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, new DocumentationReporter().getSQLTypeName());
17-
Assert.assertEquals(CustomTypes.UT_SONAR_TEST_REPORTER, new SonarTestReporter().getSQLTypeName());
18-
Assert.assertEquals(CustomTypes.UT_TEAMCITY_REPORTER, new TeamCityReporter().getSQLTypeName());
19-
Assert.assertEquals(CustomTypes.UT_XUNIT_REPORTER, new XUnitReporter().getSQLTypeName());
15+
assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, new CoverageHTMLReporter().getSQLTypeName());
16+
assertEquals(CustomTypes.UT_COVERAGE_SONAR_REPORTER, new CoverageSonarReporter().getSQLTypeName());
17+
assertEquals(CustomTypes.UT_COVERALLS_REPORTER, new CoverallsReporter().getSQLTypeName());
18+
assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, new DocumentationReporter().getSQLTypeName());
19+
assertEquals(CustomTypes.UT_SONAR_TEST_REPORTER, new SonarTestReporter().getSQLTypeName());
20+
assertEquals(CustomTypes.UT_TEAMCITY_REPORTER, new TeamCityReporter().getSQLTypeName());
21+
assertEquals(CustomTypes.UT_XUNIT_REPORTER, new XUnitReporter().getSQLTypeName());
2022
}
2123

2224
@Test
2325
public void reporterFactory() {
24-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_HTML_REPORTER)
26+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_HTML_REPORTER)
2527
instanceof CoverageHTMLReporter);
26-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_SONAR_REPORTER)
28+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_SONAR_REPORTER)
2729
instanceof CoverageSonarReporter);
28-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERALLS_REPORTER)
30+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERALLS_REPORTER)
2931
instanceof CoverallsReporter);
30-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_DOCUMENTATION_REPORTER)
32+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_DOCUMENTATION_REPORTER)
3133
instanceof DocumentationReporter);
32-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_SONAR_TEST_REPORTER)
34+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_SONAR_TEST_REPORTER)
3335
instanceof SonarTestReporter);
34-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_TEAMCITY_REPORTER)
36+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_TEAMCITY_REPORTER)
3537
instanceof TeamCityReporter);
36-
Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_XUNIT_REPORTER)
38+
assertTrue(ReporterFactory.createReporter(CustomTypes.UT_XUNIT_REPORTER)
3739
instanceof XUnitReporter);
3840
}
3941

src/test/java/org/utplsql/api/TestRunnerIT.java

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

3-
import org.junit.Assert;
43
import org.junit.Rule;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
65
import org.utplsql.api.compatibility.CompatibilityProxy;
76
import org.utplsql.api.exception.SomeTestsFailedException;
87
import org.utplsql.api.reporter.*;
@@ -11,6 +10,8 @@
1110
import java.sql.Connection;
1211
import java.sql.SQLException;
1312

13+
import static org.junit.jupiter.api.Assertions.fail;
14+
1415
/**
1516
* Created by Vinicius on 13/04/2017.
1617
*/
@@ -25,7 +26,7 @@ public void runWithDefaultParameters() {
2526
Connection conn = db.newConnection();
2627
new TestRunner().run(conn);
2728
} catch (SQLException e) {
28-
Assert.fail(e.getMessage());
29+
fail(e);
2930
}
3031
}
3132

@@ -43,7 +44,7 @@ public void runWithoutCompatibilityCheck() {
4344
.run(conn);
4445
}
4546
} catch (Exception e) {
46-
Assert.fail(e.getMessage());
47+
fail(e);
4748
}
4849
}
4950

@@ -62,7 +63,7 @@ public void runWithManyReporters() {
6263
.addReporter(new XUnitReporter().init(conn))
6364
.run(conn);
6465
} catch (SQLException e) {
65-
Assert.fail(e.getMessage());
66+
fail(e);
6667
}
6768
}
6869

@@ -79,12 +80,12 @@ public void failOnErrors() {
7980
new TestRunner()
8081
.failOnErrors(true)
8182
.run(conn);
82-
Assert.fail();
83+
fail("Test expected to throw exception");
8384
}
8485
} catch (SomeTestsFailedException ignored) {
8586
System.out.println("Expected exception object thrown.");
8687
} catch (Exception e) {
87-
Assert.fail("Wrong exception object thrown: " + e.getMessage());
88+
fail("Wrong exception object thrown: " + e.getMessage());
8889
}
8990
}
9091

0 commit comments

Comments
 (0)