Skip to content

Commit ff0b270

Browse files
committed
Test for Sonar encoding output (Version >= 3.1.2)
1 parent a3db7da commit ff0b270

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,15 @@ private void validateReporter(Connection conn, Reporter reporter) throws SQLExce
180180
reporter.init(conn, compatibilityProxy, reporterFactory);
181181
}
182182

183+
/** Returns the databaseVersion the TestRunner was run against
184+
*
185+
* @return Version of the database the TestRunner was run against
186+
*/
187+
public Version getUsedDatabaseVersion() {
188+
if ( compatibilityProxy != null )
189+
return compatibilityProxy.getDatabaseVersion();
190+
else
191+
return null;
192+
}
193+
183194
}

Diff for: src/test/java/org/utplsql/api/OutputBufferIT.java

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

33
import org.junit.jupiter.api.Test;
4+
import org.utplsql.api.compatibility.CompatibilityProxy;
5+
import org.utplsql.api.exception.InvalidVersionException;
46
import org.utplsql.api.reporter.CoreReporters;
57
import org.utplsql.api.reporter.DefaultReporter;
68
import org.utplsql.api.reporter.DocumentationReporter;
@@ -9,6 +11,7 @@
911
import java.io.File;
1012
import java.io.FileOutputStream;
1113
import java.io.PrintStream;
14+
import java.nio.charset.Charset;
1215
import java.sql.SQLException;
1316
import java.util.ArrayList;
1417
import java.util.List;
@@ -106,7 +109,7 @@ public void fetchAllLines() throws SQLException {
106109
}
107110

108111
@Test
109-
public void getOutputFromSonarReporter() throws SQLException {
112+
public void getOutputFromSonarReporter() throws SQLException, InvalidVersionException {
110113
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(newConnection());
111114

112115
new TestRunner()
@@ -119,4 +122,23 @@ public void getOutputFromSonarReporter() throws SQLException {
119122
assertTrue(outputLines.size() > 0);
120123
}
121124

125+
@Test
126+
public void sonarReporterHasEncodingSet() throws SQLException, InvalidVersionException {
127+
CompatibilityProxy proxy = new CompatibilityProxy(newConnection());
128+
129+
if ( proxy.getDatabaseVersion().isGreaterOrEqualThan(new Version("3.1.2"))) {
130+
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(getConnection());
131+
132+
TestRunner tr = new TestRunner()
133+
.addPath(getUser())
134+
.addReporter(reporter);
135+
136+
tr.run(getConnection());
137+
138+
List<String> outputLines = reporter.getOutputBuffer().fetchAll(getConnection());
139+
140+
assertTrue(outputLines.get(0).contains("encoding=\"" + Charset.defaultCharset().toString() + "\""));
141+
}
142+
143+
}
122144
}

0 commit comments

Comments
 (0)