1
1
package com .fasterxml .jackson .core ;
2
2
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
-
7
3
/**
8
4
* Unit tests for class {@link ErrorReportConfiguration}.
9
5
*
10
6
* @since 2.16
11
7
*/
12
8
public class ErrorReportConfigurationTest
9
+ extends BaseTest
13
10
{
14
-
15
11
private final ErrorReportConfiguration DEFAULTS = ErrorReportConfiguration .defaults ();
16
12
17
- @ Test
18
13
public void testNormalBuild ()
19
14
{
20
15
ErrorReportConfiguration config = ErrorReportConfiguration .builder ()
@@ -26,40 +21,37 @@ public void testNormalBuild()
26
21
assertEquals (2008 , config .getMaxRawContentLength ());
27
22
}
28
23
29
- @ Test
30
24
public void testZeroLengths ()
31
25
{
32
26
// boundary tests, because we throw error on negative values
33
27
ErrorReportConfiguration config = ErrorReportConfiguration .builder ()
34
28
.maxErrorTokenLength (0 )
35
29
.maxRawContentLength (0 )
36
30
.build ();
37
-
31
+
38
32
assertEquals (0 , config .getMaxErrorTokenLength ());
39
33
assertEquals (0 , config .getMaxRawContentLength ());
40
34
}
41
35
42
- @ Test
43
36
public void testInvalidMaxErrorTokenLength ()
44
37
{
45
38
ErrorReportConfiguration .Builder builder = ErrorReportConfiguration .builder ();
46
-
47
39
try {
48
40
builder .maxErrorTokenLength (-1 );
49
41
fail ("Should not reach here as exception is expected" );
50
42
} catch (IllegalArgumentException ex ) {
51
- // expected
43
+ verifyException (ex , "Value of maxErrorTokenLength" );
44
+ verifyException (ex , "cannot be negative" );
52
45
}
53
-
54
46
try {
55
47
builder .maxRawContentLength (-1 );
56
48
fail ("Should not reach here as exception is expected" );
57
49
} catch (IllegalArgumentException ex ) {
58
- // expected
50
+ verifyException (ex , "Value of maxRawContentLength" );
51
+ verifyException (ex , "cannot be negative" );
59
52
}
60
53
}
61
54
62
- @ Test
63
55
public void testDefaults ()
64
56
{
65
57
// default value
@@ -70,68 +62,54 @@ public void testDefaults()
70
62
assertEquals (ErrorReportConfiguration .defaults (), ErrorReportConfiguration .defaults ());
71
63
}
72
64
73
- @ Test
74
65
public void testOverrideDefaultErrorReportConfiguration ()
75
66
{
76
67
// (1) override with null, will be no change
77
68
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
+ }
101
93
}
102
94
103
- @ Test
104
95
public void testRebuild ()
105
96
{
106
97
ErrorReportConfiguration config = ErrorReportConfiguration .builder ().build ();
107
-
108
98
ErrorReportConfiguration rebuiltConfig = config .rebuild ().build ();
109
-
99
+
110
100
assertEquals (config .getMaxErrorTokenLength (), rebuiltConfig .getMaxErrorTokenLength ());
111
101
assertEquals (config .getMaxRawContentLength (), rebuiltConfig .getMaxRawContentLength ());
112
102
}
113
103
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
126
104
public void testBuilderConstructorWithErrorReportConfiguration ()
127
105
{
128
106
ErrorReportConfiguration configA = ErrorReportConfiguration .builder ()
129
107
.maxErrorTokenLength (1234 )
130
108
.maxRawContentLength (5678 )
131
109
.build ();
132
-
110
+
133
111
ErrorReportConfiguration configB = new ErrorReportConfiguration .Builder (configA ).build ();
134
-
112
+
135
113
assertEquals (configA .getMaxErrorTokenLength (), configB .getMaxErrorTokenLength ());
136
114
assertEquals (configA .getMaxRawContentLength (), configB .getMaxRawContentLength ());
137
115
}
0 commit comments