Skip to content

Commit 3155455

Browse files
committed
minor test tweaks
1 parent 75b060e commit 3155455

File tree

1 file changed

+33
-55
lines changed

1 file changed

+33
-55
lines changed

src/test/java/com/fasterxml/jackson/core/ErrorReportConfigurationTest.java

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.fasterxml.jackson.core;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.fail;
5-
import org.junit.jupiter.api.Test;
6-
73
/**
84
* Unit tests for class {@link ErrorReportConfiguration}.
95
*
106
* @since 2.16
117
*/
128
public class ErrorReportConfigurationTest
9+
extends BaseTest
1310
{
14-
1511
private final ErrorReportConfiguration DEFAULTS = ErrorReportConfiguration.defaults();
1612

17-
@Test
1813
public void testNormalBuild()
1914
{
2015
ErrorReportConfiguration config = ErrorReportConfiguration.builder()
@@ -26,40 +21,37 @@ public void testNormalBuild()
2621
assertEquals(2008, config.getMaxRawContentLength());
2722
}
2823

29-
@Test
3024
public void testZeroLengths()
3125
{
3226
// boundary tests, because we throw error on negative values
3327
ErrorReportConfiguration config = ErrorReportConfiguration.builder()
3428
.maxErrorTokenLength(0)
3529
.maxRawContentLength(0)
3630
.build();
37-
31+
3832
assertEquals(0, config.getMaxErrorTokenLength());
3933
assertEquals(0, config.getMaxRawContentLength());
4034
}
4135

42-
@Test
4336
public void testInvalidMaxErrorTokenLength()
4437
{
4538
ErrorReportConfiguration.Builder builder = ErrorReportConfiguration.builder();
46-
4739
try {
4840
builder.maxErrorTokenLength(-1);
4941
fail("Should not reach here as exception is expected");
5042
} catch (IllegalArgumentException ex) {
51-
// expected
43+
verifyException(ex, "Value of maxErrorTokenLength");
44+
verifyException(ex, "cannot be negative");
5245
}
53-
5446
try {
5547
builder.maxRawContentLength(-1);
5648
fail("Should not reach here as exception is expected");
5749
} catch (IllegalArgumentException ex) {
58-
// expected
50+
verifyException(ex, "Value of maxRawContentLength");
51+
verifyException(ex, "cannot be negative");
5952
}
6053
}
6154

62-
@Test
6355
public void testDefaults()
6456
{
6557
// default value
@@ -70,68 +62,54 @@ public void testDefaults()
7062
assertEquals(ErrorReportConfiguration.defaults(), ErrorReportConfiguration.defaults());
7163
}
7264

73-
@Test
7465
public void testOverrideDefaultErrorReportConfiguration()
7566
{
7667
// (1) override with null, will be no change
7768
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(null);
78-
79-
ErrorReportConfiguration nullDefaults = ErrorReportConfiguration.defaults();
80-
81-
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, nullDefaults.getMaxErrorTokenLength());
82-
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, nullDefaults.getMaxRawContentLength());
83-
84-
// (2) override wiht other value that actually changes default values
85-
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(ErrorReportConfiguration.builder()
86-
.maxErrorTokenLength(10101)
87-
.maxRawContentLength(20202)
88-
.build());
89-
90-
ErrorReportConfiguration overrideDefaults = ErrorReportConfiguration.defaults();
91-
92-
assertEquals(10101, overrideDefaults.getMaxErrorTokenLength());
93-
assertEquals(20202, overrideDefaults.getMaxRawContentLength());
94-
95-
// (3) revert back to default values
96-
// IMPORTANT : make sure to revert back, otherwise other tests will be affected
97-
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(ErrorReportConfiguration.builder()
98-
.maxErrorTokenLength(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH)
99-
.maxRawContentLength(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH)
100-
.build());
69+
try {
70+
ErrorReportConfiguration nullDefaults = ErrorReportConfiguration.defaults();
71+
72+
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, nullDefaults.getMaxErrorTokenLength());
73+
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, nullDefaults.getMaxRawContentLength());
74+
75+
// (2) override with other value that actually changes default values
76+
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(ErrorReportConfiguration.builder()
77+
.maxErrorTokenLength(10101)
78+
.maxRawContentLength(20202)
79+
.build());
80+
81+
ErrorReportConfiguration overrideDefaults = ErrorReportConfiguration.defaults();
82+
83+
assertEquals(10101, overrideDefaults.getMaxErrorTokenLength());
84+
assertEquals(20202, overrideDefaults.getMaxRawContentLength());
85+
} finally {
86+
// (3) revert back to default values
87+
// IMPORTANT : make sure to revert back, otherwise other tests will be affected
88+
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(ErrorReportConfiguration.builder()
89+
.maxErrorTokenLength(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH)
90+
.maxRawContentLength(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH)
91+
.build());
92+
}
10193
}
10294

103-
@Test
10495
public void testRebuild()
10596
{
10697
ErrorReportConfiguration config = ErrorReportConfiguration.builder().build();
107-
10898
ErrorReportConfiguration rebuiltConfig = config.rebuild().build();
109-
99+
110100
assertEquals(config.getMaxErrorTokenLength(), rebuiltConfig.getMaxErrorTokenLength());
111101
assertEquals(config.getMaxRawContentLength(), rebuiltConfig.getMaxRawContentLength());
112102
}
113103

114-
115-
@Test
116-
public void testBuilderConstructorWithTwoParams()
117-
{
118-
ErrorReportConfiguration config = new ErrorReportConfiguration.Builder(1313, 2424)
119-
.build();
120-
121-
assertEquals(1313, config.getMaxErrorTokenLength());
122-
assertEquals(2424, config.getMaxRawContentLength());
123-
}
124-
125-
@Test
126104
public void testBuilderConstructorWithErrorReportConfiguration()
127105
{
128106
ErrorReportConfiguration configA = ErrorReportConfiguration.builder()
129107
.maxErrorTokenLength(1234)
130108
.maxRawContentLength(5678)
131109
.build();
132-
110+
133111
ErrorReportConfiguration configB = new ErrorReportConfiguration.Builder(configA).build();
134-
112+
135113
assertEquals(configA.getMaxErrorTokenLength(), configB.getMaxErrorTokenLength());
136114
assertEquals(configA.getMaxRawContentLength(), configB.getMaxRawContentLength());
137115
}

0 commit comments

Comments
 (0)