Skip to content

Commit b708147

Browse files
committed
Add a test case for failure in character encoding detection
1 parent 1a99e58 commit b708147

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## 2.1.0 - 2021-01-23
88
### Added
99
* Tests for JSON patch move operation on nonexistent value.
10+
* Test case for failure of character encoding detection.
1011

1112
### Changed
1213
* Add operation on empty JSON pointer to structure type now accepts both array and object. This change is due to the requirement in the TCK.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The jar-packaged artifact of this test suite is available from [JitPack] reposit
3434
<dependency>
3535
<groupId>org.leadpony</groupId>
3636
<artifactId>jsonp-test-suite</artifactId>
37-
<version>2.0.0</version>
37+
<version>2.1.0</version>
3838
<scope>test</scope>
3939
</dependency>
4040
</dependencies>
@@ -84,7 +84,7 @@ mvn test -P test-with-joy
8484
```
8585

8686
## Copyright Notice
87-
Copyright 2019-2020 the original author or authors. All rights reserved.
87+
Copyright 2019-2021 the original author or authors. All rights reserved.
8888

8989
Licensed under the Apache License, Version 2.0 (the "License");
9090
you may not use this product except in compliance with the License.

pom.xml

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

66
<groupId>org.leadpony</groupId>
77
<artifactId>jsonp-test-suite</artifactId>
8-
<version>2.1.0-SNAPSHOT</version>
8+
<version>2.1.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>JSON-P Test Suite</name>
@@ -244,7 +244,7 @@
244244
<dependency>
245245
<groupId>org.leadpony.joy</groupId>
246246
<artifactId>joy-classic</artifactId>
247-
<version>2.0.0</version>
247+
<version>2.1.0</version>
248248
<scope>test</scope>
249249
</dependency>
250250
</dependencies>

src/main/java/org/leadpony/jsonp/testsuite/tests/CharsetDetectionTest.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 the JSON-P Test Suite Authors.
2+
* Copyright 2019-2021 the JSON-P Test Suite Authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,9 @@
1515
*/
1616
package org.leadpony.jsonp.testsuite.tests;
1717

18+
import static org.assertj.core.api.Assertions.assertThat;
1819
import static org.assertj.core.api.Assertions.assertThatCode;
20+
import static org.assertj.core.api.Assertions.catchThrowable;
1921

2022
import java.io.ByteArrayInputStream;
2123
import java.io.InputStream;
@@ -24,10 +26,12 @@
2426
import java.nio.charset.StandardCharsets;
2527

2628
import jakarta.json.Json;
29+
import jakarta.json.JsonException;
2730
import jakarta.json.stream.JsonParser;
2831
import jakarta.json.stream.JsonParserFactory;
2932

3033
import org.junit.jupiter.api.BeforeAll;
34+
import org.junit.jupiter.api.Test;
3135
import org.junit.jupiter.params.ParameterizedTest;
3236
import org.junit.jupiter.params.provider.EnumSource;
3337

@@ -112,19 +116,27 @@ public void utf32leWithBom(JsonTestCase test) {
112116
testParser(test, UTF_32LE, UTF_32LE_BOM);
113117
}
114118

119+
@Test
120+
public void shouldFailToDetectEncoding() {
121+
byte[] bytes = {0x00};
122+
InputStream in = new ByteArrayInputStream(bytes);
123+
Throwable thrown = catchThrowable(() -> {
124+
parserFactory.createParser(in);
125+
});
126+
assertThat(thrown).isInstanceOf(JsonException.class);
127+
}
128+
115129
private void testParser(JsonTestCase test, Charset charset) {
116130
InputStream in = createEncodedStream(test.getJson(), charset);
117-
assertThatCode(() -> {
118-
JsonParser parser = parserFactory.createParser(in);
119-
while (parser.hasNext()) {
120-
parser.next();
121-
}
122-
parser.close();
123-
}).doesNotThrowAnyException();
131+
testParserWithStream(in);
124132
}
125133

126134
private void testParser(JsonTestCase test, Charset charset, byte[] bom) {
127135
InputStream in = createEncodedStream(test.getJson(), charset, bom);
136+
testParserWithStream(in);
137+
}
138+
139+
private void testParserWithStream(InputStream in) {
128140
assertThatCode(() -> {
129141
JsonParser parser = parserFactory.createParser(in);
130142
while (parser.hasNext()) {

0 commit comments

Comments
 (0)