Skip to content

Commit bbe99e4

Browse files
committed
Use Java 17
1 parent 8ccd9f2 commit bbe99e4

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

java/src/main/java/io/cucumber/junitxmlformatter/EscapingXmlStreamWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void writeAttribute(String localName, String value) throws XMLStreamException {
5656

5757
void writeCData(String data) throws XMLStreamException {
5858
// https://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml
59-
for (String part : CDATA_TERMINATOR_SPLIT.split(data)) {
59+
for (String part : CDATA_TERMINATOR_SPLIT.split(data, -1)) {
6060
// see https://www.w3.org/TR/xml/#dt-cdsection
6161
writer.writeCData(escapeIllegalChars(part));
6262
}
@@ -88,6 +88,7 @@ private static String escapeIllegalChars(String value) {
8888
return escaped.toString();
8989
}
9090

91+
@SuppressWarnings("UnnecessaryParentheses")
9192
private static boolean isLegal(int codePoint) {
9293
// see https://www.w3.org/TR/xml/#charsets
9394
return codePoint == 0x9

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ List<TestCaseStarted> getAllTestCaseStarted() {
129129
}
130130

131131
private static final io.cucumber.messages.types.Duration ZERO_DURATION =
132-
new io.cucumber.messages.types.Duration(0L, 0L);
132+
new io.cucumber.messages.types.Duration(0L, 0);
133133
// By definition, but see https://github.com/cucumber/gherkin/issues/11
134134
private static final TestStepResult SCENARIO_WITH_NO_STEPS = new TestStepResult(ZERO_DURATION, null, PASSED, null);
135135

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void writeSuiteAttributes(EscapingXmlStreamWriter writer) throws XMLStre
5353
Map<TestStepResultStatus, Long> counts = data.getTestCaseStatusCounts();
5454

5555
writer.writeAttribute("tests", String.valueOf(data.getTestCaseCount()));
56-
writer.writeAttribute("skipped", counts.get(SKIPPED).toString());
56+
writer.writeAttribute("skipped", String.valueOf(counts.get(SKIPPED)));
5757
writer.writeAttribute("failures", String.valueOf(countFailures(counts)));
5858
writer.writeAttribute("errors", "0");
5959

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.cucumber.junitxmlformatter;
3+
4+
import org.jspecify.annotations.NullMarked;

java/src/test/java/io/cucumber/junitxmlformatter/Jackson.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.cucumber.junitxmlformatter;
22

33
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
4-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
54
import com.fasterxml.jackson.core.JsonGenerator;
65
import com.fasterxml.jackson.databind.DeserializationFeature;
76
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -11,6 +10,9 @@
1110
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
1211
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
1312

13+
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_ABSENT;
14+
import static com.fasterxml.jackson.annotation.JsonInclude.Value.construct;
15+
1416
final class Jackson {
1517
public static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
1618
.addModule(new Jdk8Module())

java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import java.util.stream.Stream;
2929

3030
import static io.cucumber.junitxmlformatter.Jackson.OBJECT_MAPPER;
31+
import static java.util.Objects.requireNonNull;
3132
import static org.xmlunit.assertj.XmlAssert.assertThat;
3233

3334
class MessagesToJunitXmlWriterAcceptanceTest {
34-
private static final NdjsonToMessageIterable.Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class);
35+
private static final NdjsonToMessageIterable.Deserializer deserializer = json -> OBJECT_MAPPER.readValue(json, Envelope.class);
3536

3637
static List<TestCase> acceptance() throws IOException {
3738
try (Stream<Path> paths = Files.list(Paths.get("../testdata/src"))) {
@@ -107,14 +108,13 @@ private static <T extends OutputStream> T writeJunitXmlReport(TestCase testCase,
107108
static class TestCase {
108109
private final Path source;
109110
private final Path expected;
110-
111111
private final String name;
112112

113113
TestCase(Path source) {
114114
this.source = source;
115115
String fileName = source.getFileName().toString();
116116
this.name = fileName.substring(0, fileName.lastIndexOf(".ndjson"));
117-
this.expected = source.getParent().resolve(name + ".xml");
117+
this.expected = requireNonNull(source.getParent()).resolve(name + ".xml");
118118
}
119119

120120
@Override
@@ -124,15 +124,13 @@ public String toString() {
124124

125125
@Override
126126
public boolean equals(Object o) {
127-
if (this == o) return true;
128-
if (o == null || getClass() != o.getClass()) return false;
129-
TestCase testCase = (TestCase) o;
130-
return source.equals(testCase.source);
127+
if (!(o instanceof TestCase testCase)) return false;
128+
return Objects.equals(source, testCase.source) && Objects.equals(expected, testCase.expected) && Objects.equals(name, testCase.name);
131129
}
132130

133131
@Override
134132
public int hashCode() {
135-
return Objects.hash(source);
133+
return Objects.hash(source, expected, name);
136134
}
137135
}
138136

java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.cucumber.messages.types.Envelope;
44
import io.cucumber.messages.types.TestRunFinished;
55
import io.cucumber.messages.types.TestRunStarted;
6+
import io.cucumber.messages.types.Timestamp;
67
import org.junit.jupiter.api.Test;
78

89
import java.io.ByteArrayOutputStream;
@@ -48,7 +49,9 @@ void it_throws_when_writing_after_close() throws IOException {
4849
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
4950
MessagesToJunitXmlWriter messagesToHtmlWriter = new MessagesToJunitXmlWriter(bytes);
5051
messagesToHtmlWriter.close();
51-
assertThrows(IOException.class, () -> messagesToHtmlWriter.write(null));
52+
assertThrows(IOException.class, () -> messagesToHtmlWriter.write(
53+
Envelope.of(new TestRunStarted(new Timestamp(0L, 0), ""))
54+
));
5255
}
5356

5457
@Test

0 commit comments

Comments
 (0)