Skip to content

Commit 36050bf

Browse files
committed
Some more test improvements
1 parent c896ac9 commit 36050bf

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/main/java/com/fasterxml/jackson/core/TSFBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ protected TSFBuilder() {
105105
_streamWriteFeatures = DEFAULT_GENERATOR_FEATURE_FLAGS;
106106
_inputDecorator = null;
107107
_outputDecorator = null;
108+
_generatorDecorators = null;
108109
}
109110

110111
protected TSFBuilder(JsonFactory base)
111112
{
112113
this(base._factoryFeatures,
113114
base._parserFeatures, base._generatorFeatures);
114115
_streamReadConstraints = base._streamReadConstraints;
116+
_inputDecorator = base._inputDecorator;
117+
_outputDecorator = base._outputDecorator;
118+
_generatorDecorators = _copy(base._generatorDecorators);
115119
}
116120

117121
protected TSFBuilder(int factoryFeatures,
@@ -122,6 +126,14 @@ protected TSFBuilder(int factoryFeatures,
122126
_streamWriteFeatures = generatorFeatures;
123127
}
124128

129+
// @since 2.16
130+
protected static <T> List<T> _copy(List<T> src) {
131+
if (src == null) {
132+
return src;
133+
}
134+
return new ArrayList<T>(src);
135+
}
136+
125137
// // // Accessors
126138

127139
public int factoryFeaturesMask() { return _factoryFeatures; }

src/test/java/com/fasterxml/jackson/core/json/TestDecorators.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,47 @@ public void testDeprecatedMethods() throws IOException
170170
/**********************************************************
171171
*/
172172

173-
public void testGeneratorDecoration() throws IOException
173+
public void testGeneratorDecoration() throws Exception
174174
{
175175
JsonFactory f = JsonFactory.builder()
176176
.decorateWith(new SimpleGeneratorDecorator())
177177
.build();
178+
final String EXP = a2q("{'password':'***'}");
178179

180+
// First, test with newly constructed factory
179181
StringWriter sw = new StringWriter();
180182
try (JsonGenerator g = f.createGenerator(sw)) {
181-
g.writeStartObject();
182-
g.writeStringField("password", "s3cr37!!!");
183-
g.writeEndObject();
183+
_generateForDecorator(g);
184184
}
185-
assertEquals(a2q("{'password':'***'}"), sw.toString());
185+
assertEquals(EXP, sw.toString());
186186

187187
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
188188
try (JsonGenerator g = f.createGenerator(bytes)) {
189-
g.writeStartObject();
190-
g.writeStringField("password", "s3cr37x!!");
191-
g.writeEndObject();
189+
_generateForDecorator(g);
192190
}
193-
assertEquals(a2q("{'password':'***'}"), utf8String(bytes));
191+
assertEquals(EXP, utf8String(bytes));
192+
193+
// Second do the same to a copy
194+
JsonFactory f2 = f.copy();
195+
sw = new StringWriter();
196+
try (JsonGenerator g = f2.createGenerator(sw)) {
197+
_generateForDecorator(g);
198+
}
199+
assertEquals(EXP, sw.toString());
200+
201+
// And re-built instance
202+
JsonFactory f3 = f2.rebuild().build();
203+
sw = new StringWriter();
204+
try (JsonGenerator g = f3.createGenerator(sw)) {
205+
_generateForDecorator(g);
206+
}
207+
assertEquals(EXP, sw.toString());
194208
}
195209

210+
private void _generateForDecorator(JsonGenerator g) throws Exception
211+
{
212+
g.writeStartObject();
213+
g.writeStringField("password", "s3cr37x!!");
214+
g.writeEndObject();
215+
}
196216
}

0 commit comments

Comments
 (0)