diff --git a/src/test/java/com/fasterxml/jackson/core/ErrorReportConfigurationTest.java b/src/test/java/com/fasterxml/jackson/core/ErrorReportConfigurationTest.java index 48458ba0e1..363d13e6e8 100644 --- a/src/test/java/com/fasterxml/jackson/core/ErrorReportConfigurationTest.java +++ b/src/test/java/com/fasterxml/jackson/core/ErrorReportConfigurationTest.java @@ -4,16 +4,24 @@ import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; +/** + * Unit tests for class {@link ErrorReportConfiguration}. + * + * @since 2.16 + */ public class ErrorReportConfigurationTest { + private final ErrorReportConfiguration DEFAULTS = ErrorReportConfiguration.defaults(); + @Test - public void testMaxErrorTokenLength() + public void testZeroLengths() { ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder(); - int maxLength = 128; - builder.maxErrorTokenLength(maxLength); + builder.maxErrorTokenLength(0); + builder.maxRawContentLength(0); ErrorReportConfiguration config = builder.build(); - assertEquals(maxLength, config.getMaxErrorTokenLength()); + assertEquals(0, config.getMaxErrorTokenLength()); + assertEquals(0, config.getMaxRawContentLength()); } @Test @@ -53,11 +61,9 @@ public void testInvalidMaxRawContentLength() @Test public void testDefaults() { - ErrorReportConfiguration config = ErrorReportConfiguration.defaults(); - // default value - assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, config.getMaxErrorTokenLength()); - assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, config.getMaxRawContentLength()); + assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULTS.getMaxErrorTokenLength()); + assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, DEFAULTS.getMaxRawContentLength()); // equals assertEquals(ErrorReportConfiguration.defaults(), ErrorReportConfiguration.defaults()); @@ -66,23 +72,26 @@ public void testDefaults() @Test public void testOverrideDefaultErrorReportConfiguration() { - // try override static - ErrorReportConfiguration newConfig = new ErrorReportConfiguration.Builder() + // try with null, no change + ErrorReportConfiguration nullDefaults = ErrorReportConfiguration.defaults(); + ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(null); + assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, nullDefaults.getMaxErrorTokenLength()); + assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, nullDefaults.getMaxRawContentLength()); + + // try override defaults + ErrorReportConfiguration overrideDefaults = new ErrorReportConfiguration.Builder() .maxErrorTokenLength(128) .maxRawContentLength(256) .build(); - ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(newConfig); - - ErrorReportConfiguration config = ErrorReportConfiguration.defaults(); - assertEquals(128, config.getMaxErrorTokenLength()); - assertEquals(256, config.getMaxRawContentLength()); + ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(overrideDefaults); + assertEquals(128, overrideDefaults.getMaxErrorTokenLength()); + assertEquals(256, overrideDefaults.getMaxRawContentLength()); // IMPORTANT : make sure to revert back, otherwise other tests will be affected - ErrorReportConfiguration defaultConfig = new ErrorReportConfiguration.Builder() + ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(new ErrorReportConfiguration.Builder() .maxErrorTokenLength(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH) .maxRawContentLength(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH) - .build(); - ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(defaultConfig); + .build()); } @Test @@ -93,4 +102,27 @@ public void testRebuild() assertEquals(config.getMaxErrorTokenLength(), rebuiltConfig.getMaxErrorTokenLength()); assertEquals(config.getMaxRawContentLength(), rebuiltConfig.getMaxRawContentLength()); } + + + @Test + public void testBuilderConstructorWithTwoParams() + { + ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder(128, 256); + ErrorReportConfiguration config = builder.build(); + assertEquals(128, config.getMaxErrorTokenLength()); + assertEquals(256, config.getMaxRawContentLength()); + } + + @Test + public void testBuilderConstructorWithErrorReportConfiguration() + { + ErrorReportConfiguration newConfig = new ErrorReportConfiguration.Builder() + .maxErrorTokenLength(128) + .maxRawContentLength(256) + .build(); + ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder(newConfig); + ErrorReportConfiguration config = builder.build(); + assertEquals(newConfig.getMaxErrorTokenLength(), config.getMaxErrorTokenLength()); + assertEquals(newConfig.getMaxRawContentLength(), config.getMaxRawContentLength()); + } }