Skip to content

Commit

Permalink
Further minor test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 14, 2023
1 parent d22c2b0 commit ea85072
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class CSVBigStringsTest extends ModuleTestBase
{
private final CsvMapper MAPPER = mapperForCsv();

private final static int TOO_LONG_STRING_VALUE_LEN = 20_000_100;

private CsvMapper newCsvMapperWithUnlimitedStringSizeSupport() {
CsvFactory csvFactory = CsvFactory.builder()
.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build())
Expand All @@ -29,7 +31,7 @@ public void testBigString() throws Exception
MappingIterator<List<String>> it = MAPPER
.readerForListOf(String.class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValues(generateCsv(20_001_000));
.readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN));
it.readAll();
fail("expected DatabindException");
} catch (DatabindException e) {
Expand All @@ -45,7 +47,7 @@ public void testBiggerString() throws Exception
MappingIterator<List<String>> it = MAPPER
.readerForListOf(String.class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValues(generateCsv(21_000_000));
.readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN));
it.readAll();
fail("expected DatabindException");
} catch (DatabindException e) {
Expand All @@ -59,7 +61,7 @@ public void testBiggerString() throws Exception

public void testUnlimitedString() throws Exception
{
final int len = 5001000;
final int len = TOO_LONG_STRING_VALUE_LEN;
MappingIterator<List<String>> it = newCsvMapperWithUnlimitedStringSizeSupport()
.readerForListOf(String.class)
.with(CsvParser.Feature.WRAP_AS_ARRAY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class TomlBigStringsTest extends TomlMapperTestBase
{
private final static int TOO_LONG_STRING_VALUE_LEN = 20_000_100;

final static class StringWrapper
{
Expand Down Expand Up @@ -38,7 +39,7 @@ private TomlMapper newMapperWithUnlimitedStringSizeSupport() {
public void testBigString() throws Exception
{
try {
MAPPER.readValue(generateToml(20_001_000), StringWrapper.class);
MAPPER.readValue(generateToml(TOO_LONG_STRING_VALUE_LEN), StringWrapper.class);
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
final String message = e.getMessage();
Expand All @@ -51,7 +52,7 @@ public void testBigString() throws Exception
public void testBiggerString() throws Exception
{
try {
MAPPER.readValue(generateToml(20_100_000), StringWrapper.class);
MAPPER.readValue(generateToml(TOO_LONG_STRING_VALUE_LEN), StringWrapper.class);
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
final String message = e.getMessage();
Expand All @@ -65,7 +66,7 @@ public void testBiggerString() throws Exception
@Test
public void testUnlimitedString() throws Exception
{
final int len = 5001000;
final int len = TOO_LONG_STRING_VALUE_LEN;
StringWrapper sw = newMapperWithUnlimitedStringSizeSupport()
.readValue(generateToml(len), StringWrapper.class);
assertEquals(len, sw.string.length());
Expand Down

0 comments on commit ea85072

Please sign in to comment.