Skip to content

Commit

Permalink
Fix broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 12, 2024
1 parent 9c13ad0 commit 211874d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.List;

import tools.jackson.core.StreamReadConstraints;
import tools.jackson.databind.DatabindException;
import tools.jackson.core.exc.StreamConstraintsException;

import tools.jackson.databind.MappingIterator;

import tools.jackson.dataformat.csv.CsvFactory;
import tools.jackson.dataformat.csv.CsvMapper;
import tools.jackson.dataformat.csv.CsvParser;
Expand Down Expand Up @@ -32,8 +34,8 @@ public void testBigString() throws Exception
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN));
it.readAll();
fail("expected DatabindException");
} catch (DatabindException e) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
final String message = e.getMessage();
assertTrue("unexpected exception message: " + message, message.startsWith("String value length"));
assertTrue("unexpected exception message: " + message, message.contains("exceeds the maximum allowed ("));
Expand All @@ -48,8 +50,8 @@ public void testBiggerString() throws Exception
.with(CsvParser.Feature.WRAP_AS_ARRAY)
.readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN));
it.readAll();
fail("expected DatabindException");
} catch (DatabindException e) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
final String message = e.getMessage();
// this test fails when the TextBuffer is being resized, so we don't yet know just how big the string is
// so best not to assert that the String length value in the message is the full 20_000_000 value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;

import tools.jackson.core.StreamReadConstraints;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.databind.DatabindException;
import tools.jackson.dataformat.csv.CsvFactory;
import tools.jackson.dataformat.csv.CsvMapper;
Expand Down Expand Up @@ -77,8 +78,8 @@ public void testVeryBigDecimalUnwrapped() throws Exception
MAPPER.readerFor(NestedBigDecimalHolder2784.class)
.with(schema)
.readValue(DOC);
fail("expected JsonMappingException");
} catch (DatabindException jme) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException jme) {
assertTrue("unexpected message: " + jme.getMessage(),
jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import tools.jackson.core.JacksonException;

import tools.jackson.core.StreamWriteFeature;
import tools.jackson.databind.DatabindException;

import tools.jackson.dataformat.csv.CsvMapper;
import tools.jackson.dataformat.csv.CsvSchema;
import tools.jackson.dataformat.csv.CsvWriteException;
Expand Down Expand Up @@ -78,16 +78,10 @@ public void testIgnoreEmbeddedObject() throws Exception
try {
mapper.writer(schema).writeValue(sw, myClass);
fail("Should not pass");
} catch (JacksonException e) {
assertTrue(e instanceof DatabindException);
} catch (CsvWriteException e) {
// 23-Jan-2021, tatu: Not ideal that this gets wrapped, but let's verify contents
verifyException(e, "CSV generator does not support");
verifyException(e, "nested Objects");

// and that there's linked root cause
Throwable rootCause = e.getCause();
assertTrue(rootCause instanceof CsvWriteException);
verifyException(rootCause, "nested Objects");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.List;

import tools.jackson.core.StreamWriteConstraints;
import tools.jackson.core.exc.StreamConstraintsException;

import tools.jackson.databind.DatabindException;
import tools.jackson.dataformat.csv.CsvMapper;
import tools.jackson.dataformat.csv.ModuleTestBase;

Expand All @@ -22,8 +22,8 @@ public void testListWithSelfReference() throws Exception {
list.add(list);
try {
MAPPER.writeValueAsString(list);
fail("expected DatabindException");
} catch (DatabindException e) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
assertTrue("DatabindException message is as expected?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;

import tools.jackson.core.StreamReadConstraints;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;

Expand Down Expand Up @@ -93,10 +94,10 @@ public void testVeryBigDecimalUnwrapped() throws Exception
final String DOC = "value: " + value;
try {
MAPPER.readValue(DOC, NestedBigDecimalHolder2784.class);
fail("expected DatabindException");
} catch (DatabindException jme) {
assertTrue("unexpected message: " + jme.getMessage(),
jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed"));
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
assertTrue("unexpected message: " + e.getMessage(),
e.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.List;

import tools.jackson.core.StreamWriteConstraints;
import tools.jackson.core.exc.StreamConstraintsException;

import tools.jackson.databind.DatabindException;
import tools.jackson.dataformat.javaprop.JavaPropsMapper;
import tools.jackson.dataformat.javaprop.ModuleTestBase;

Expand All @@ -22,8 +22,8 @@ public void testListWithSelfReference() throws Exception {
list.add(list);
try {
MAPPER.writeValueAsString(list);
fail("expected DatabindException");
} catch (DatabindException e) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
assertTrue("JsonMappingException message is as expected?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.ArrayList;
import java.util.List;

import tools.jackson.core.StreamWriteConstraints;
import org.junit.Test;

import tools.jackson.databind.DatabindException;
import tools.jackson.core.StreamWriteConstraints;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.dataformat.toml.TomlMapperTestBase;

import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -28,12 +27,12 @@ public void testListWithSelfReference() throws Exception {
list.add(list);
try {
MAPPER.writeValueAsString(list);
fail("expected DatabindException");
} catch (DatabindException jmex) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
assertTrue("DatabindException message is as expected?",
jmex.getMessage().startsWith(exceptionPrefix));
e.getMessage().startsWith(exceptionPrefix));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import java.util.List;

import tools.jackson.core.StreamWriteConstraints;

import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.core.exc.StreamConstraintsException;

import tools.jackson.dataformat.yaml.ModuleTestBase;
import tools.jackson.dataformat.yaml.YAMLMapper;
Expand All @@ -17,15 +15,15 @@
*/
public class CyclicYAMLDataSerTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = YAMLMapper.builder().build();
private final YAMLMapper MAPPER = YAMLMapper.builder().build();

public void testListWithSelfReference() throws Exception {
List<Object> list = new ArrayList<>();
list.add(list);
try {
MAPPER.writeValueAsString(list);
fail("expected DatabindException");
} catch (DatabindException e) {
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
assertTrue("DatabindException message is as expected?",
Expand Down

0 comments on commit 211874d

Please sign in to comment.