Skip to content

Commit

Permalink
Add a test case for failure in character encoding detection
Browse files Browse the repository at this point in the history
  • Loading branch information
leadpony committed Jan 23, 2021
1 parent 1a99e58 commit b708147
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

### Changed
* 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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The jar-packaged artifact of this test suite is available from [JitPack] reposit
<dependency>
<groupId>org.leadpony</groupId>
<artifactId>jsonp-test-suite</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -84,7 +84,7 @@ mvn test -P test-with-joy
```

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

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this product except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.leadpony</groupId>
<artifactId>jsonp-test-suite</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>JSON-P Test Suite</name>
Expand Down Expand Up @@ -244,7 +244,7 @@
<dependency>
<groupId>org.leadpony.joy</groupId>
<artifactId>joy-classic</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the JSON-P Test Suite Authors.
* Copyright 2019-2021 the JSON-P Test Suite Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,9 @@
*/
package org.leadpony.jsonp.testsuite.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -24,10 +26,12 @@
import java.nio.charset.StandardCharsets;

import jakarta.json.Json;
import jakarta.json.JsonException;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParserFactory;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

Expand Down Expand Up @@ -112,19 +116,27 @@ public void utf32leWithBom(JsonTestCase test) {
testParser(test, UTF_32LE, UTF_32LE_BOM);
}

@Test
public void shouldFailToDetectEncoding() {
byte[] bytes = {0x00};
InputStream in = new ByteArrayInputStream(bytes);
Throwable thrown = catchThrowable(() -> {
parserFactory.createParser(in);
});
assertThat(thrown).isInstanceOf(JsonException.class);
}

private void testParser(JsonTestCase test, Charset charset) {
InputStream in = createEncodedStream(test.getJson(), charset);
assertThatCode(() -> {
JsonParser parser = parserFactory.createParser(in);
while (parser.hasNext()) {
parser.next();
}
parser.close();
}).doesNotThrowAnyException();
testParserWithStream(in);
}

private void testParser(JsonTestCase test, Charset charset, byte[] bom) {
InputStream in = createEncodedStream(test.getJson(), charset, bom);
testParserWithStream(in);
}

private void testParserWithStream(InputStream in) {
assertThatCode(() -> {
JsonParser parser = parserFactory.createParser(in);
while (parser.hasNext()) {
Expand Down

0 comments on commit b708147

Please sign in to comment.