Skip to content

Commit 73eac23

Browse files
committed
test cleanup
1 parent 4dfc4cf commit 73eac23

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

json_serializable/test/generic_files/generic_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void main() {
318318
});
319319

320320
test('issue 980 regression test', () {
321-
roundTripObject(
321+
validateRoundTrip(
322322
Issue980ParentClass([
323323
Issue980GenericClass(45),
324324
Issue980GenericClass(42),

json_serializable/test/integration/integration_test.dart

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Matcher _throwsArgumentError(matcher) =>
1414
void main() {
1515
group('Person', () {
1616
void roundTripPerson(Person p) {
17-
roundTripObject(p, (json) => Person.fromJson(json));
17+
validateRoundTrip(p, (json) => Person.fromJson(json));
1818
}
1919

2020
test('now', () {
@@ -48,7 +48,7 @@ void main() {
4848

4949
group('Order', () {
5050
void roundTripOrder(Order p) {
51-
roundTripObject(p, (json) => Order.fromJson(json));
51+
validateRoundTrip(p, (json) => Order.fromJson(json));
5252
}
5353

5454
test('null', () {
@@ -187,7 +187,7 @@ void main() {
187187

188188
group('Item', () {
189189
void roundTripItem(Item p) {
190-
roundTripObject(p, (json) => Item.fromJson(json));
190+
validateRoundTrip(p, (json) => Item.fromJson(json));
191191
}
192192

193193
test('empty json', () {
@@ -228,7 +228,7 @@ void main() {
228228

229229
group('Numbers', () {
230230
void roundTripNumber(Numbers p) {
231-
roundTripObject(p, (json) => Numbers.fromJson(json));
231+
validateRoundTrip(p, (json) => Numbers.fromJson(json));
232232
}
233233

234234
test('simple', () {
@@ -273,10 +273,7 @@ void main() {
273273
..intIntMap = {3: 3}
274274
..uriIntMap = {Uri.parse('https://example.com'): 4};
275275

276-
final roundTrip =
277-
roundTripObject(instance, (j) => MapKeyVariety.fromJson(j));
278-
279-
expect(roundTrip, instance);
276+
validateRoundTrip(instance, (j) => MapKeyVariety.fromJson(j));
280277
});
281278

282279
test('UnknownEnumValue', () {

json_serializable/test/kitchen_sink/kitchen_sink_test.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void _nonNullableTests(KitchenSinkFactory factory) {
8484

8585
void _nullableTests(KitchenSinkFactory factory) {
8686
void roundTripSink(KitchenSink p) {
87-
roundTripObject(p, factory.fromJson);
87+
validateRoundTrip(p, factory.fromJson);
8888
}
8989

9090
test('nullable values are allowed in the nullable version', () {
@@ -164,7 +164,7 @@ void _nullableTests(KitchenSinkFactory factory) {
164164
void _sharedTests(KitchenSinkFactory factory) {
165165
test('empty', () {
166166
final item = factory.ctor();
167-
roundTripObject(item, factory.fromJson);
167+
validateRoundTrip(item, factory.fromJson);
168168
});
169169

170170
test('list and map of DateTime - not null', () {
@@ -173,7 +173,7 @@ void _sharedTests(KitchenSinkFactory factory) {
173173
..dateTimeList = <DateTime>[now, now]
174174
..objectDateTimeMap = <Object, DateTime>{'value': now};
175175

176-
roundTripObject(item, factory.fromJson);
176+
validateRoundTrip(item, factory.fromJson);
177177
});
178178

179179
test('complex nested type - not null', () {
@@ -191,7 +191,7 @@ void _sharedTests(KitchenSinkFactory factory) {
191191
}
192192
}
193193
];
194-
roundTripObject(item, factory.fromJson);
194+
validateRoundTrip(item, factory.fromJson);
195195
});
196196

197197
test('round trip valid, empty values', () {
@@ -210,7 +210,7 @@ void _sharedTests(KitchenSinkFactory factory) {
210210

211211
final validInstance = factory.fromJson(values);
212212

213-
roundTripObject(validInstance, factory.fromJson);
213+
validateRoundTrip(validInstance, factory.fromJson);
214214
});
215215

216216
test('JSON keys should be defined in field/property order', () {
@@ -224,7 +224,7 @@ void _sharedTests(KitchenSinkFactory factory) {
224224

225225
test('valid values round-trip - json', () {
226226
final validInstance = factory.fromJson(validValues);
227-
roundTripObject(validInstance, factory.fromJson);
227+
validateRoundTrip(validInstance, factory.fromJson);
228228
});
229229
}
230230

json_serializable/test/test_utils.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ final isTypeError = isA<TypeError>();
1515
bool deepEquals(dynamic a, dynamic b) =>
1616
const DeepCollectionEquality().equals(a, b);
1717

18-
T roundTripObject<T>(T object, T Function(Map<String, dynamic> json) factory) {
18+
void validateRoundTrip<T>(
19+
T object,
20+
T Function(Map<String, dynamic> json) factory,
21+
) {
1922
final data = loudEncode(object);
2023

2124
final object2 = factory(json.decode(data) as Map<String, dynamic>);
@@ -25,7 +28,6 @@ T roundTripObject<T>(T object, T Function(Map<String, dynamic> json) factory) {
2528
final json2 = loudEncode(object2);
2629

2730
expect(json2, equals(data));
28-
return object2;
2931
}
3032

3133
/// Prints out nested causes before throwing `JsonUnsupportedObjectError`.

0 commit comments

Comments
 (0)