Skip to content

Commit 0dd731c

Browse files
authored
General cleanup (#814)
1 parent af82671 commit 0dd731c

24 files changed

+78
-56
lines changed

_test_yaml/test/yaml_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal
160160
╵'''
161161
};
162162

163-
// ignore: deprecated_member_use
164-
final throwsCastError = throwsA(isA<CastError>());
165-
166163
T roundTripObject<T>(
167164
T object,
168165
T Function(Map<String, dynamic> json) factory, {

example/test/json_convert_example_test.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ void main() {
6767
final encoded = _encode(collection);
6868

6969
expect(
70-
() => GenericCollection<CustomResult>.fromJson(
71-
jsonDecode(encoded) as Map<String, dynamic>),
72-
_throwsCastError);
70+
() => GenericCollection<CustomResult>.fromJson(
71+
jsonDecode(encoded) as Map<String, dynamic>),
72+
_throwsTypeError,
73+
);
7374
expect(
74-
() => GenericCollection<int>.fromJson(
75-
jsonDecode(encoded) as Map<String, dynamic>),
76-
_throwsCastError);
75+
() => GenericCollection<int>.fromJson(
76+
jsonDecode(encoded) as Map<String, dynamic>),
77+
_throwsTypeError,
78+
);
7779
expect(
78-
() => GenericCollection<String>.fromJson(
79-
jsonDecode(encoded) as Map<String, dynamic>),
80-
_throwsCastError);
80+
() => GenericCollection<String>.fromJson(
81+
jsonDecode(encoded) as Map<String, dynamic>),
82+
_throwsTypeError,
83+
);
8184

8285
final collection2 =
8386
GenericCollection.fromJson(jsonDecode(encoded) as Map<String, dynamic>);
@@ -96,8 +99,7 @@ void main() {
9699
});
97100
}
98101

99-
// ignore: deprecated_member_use
100-
final _throwsCastError = throwsA(isA<CastError>());
102+
final _throwsTypeError = throwsA(isA<TypeError>());
101103

102104
String _encode(Object object) =>
103105
const JsonEncoder.withIndent(' ').convert(object);

json_serializable/test/generic_files/generic_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ void main() {
4242
});
4343
test('with bad arguments', () {
4444
expect(
45-
() => GenericClass<double, String>()
46-
..fieldT = (true as dynamic) as double,
47-
throwsCastError);
45+
() => GenericClass<double, String>()
46+
..fieldT = (true as dynamic) as double,
47+
throwsTypeError,
48+
);
4849
});
4950
test('with bad arguments', () {
5051
expect(
51-
() =>
52-
GenericClass<double, String>()..fieldS = (5 as dynamic) as String,
53-
throwsCastError);
52+
() => GenericClass<double, String>()..fieldS = (5 as dynamic) as String,
53+
throwsTypeError,
54+
);
5455
});
5556
});
5657

json_serializable/test/integration/integration_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void main() {
248248
'ints': [3.14, 0],
249249
};
250250

251-
expect(() => Numbers.fromJson(value), throwsCastError);
251+
expect(() => Numbers.fromJson(value), throwsTypeError);
252252
});
253253
});
254254

json_serializable/test/kitchen_sink/kitchen_sink_test.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void _nonNullableTests(KitchenSinkFactory factory) {
6868
if (factory.checked) {
6969
matcher = checkedMatcher('set');
7070
} else {
71-
matcher = isA<TypeError>();
71+
matcher = isTypeError;
7272
}
7373
expect(() => factory.fromJson(<String, dynamic>{}), throwsA(matcher));
7474
});
@@ -122,7 +122,9 @@ void _nullableTests(KitchenSinkFactory factory) {
122122
expect(
123123
encoded,
124124
containsPair(
125-
key, _nonNullableFields.contains(key) ? isNotNull : isNull),
125+
key,
126+
_nonNullableFields.contains(key) ? isNotNull : isNull,
127+
),
126128
);
127129
}
128130
}
@@ -228,7 +230,7 @@ void _sharedTests(KitchenSinkFactory factory) {
228230
});
229231
}
230232

231-
const _nonNullableFields = [
233+
const _nonNullableFields = {
232234
'dynamicIterable',
233235
'objectIterable',
234236
'intIterable',
@@ -251,11 +253,11 @@ const _nonNullableFields = [
251253
'val',
252254
'simpleObject',
253255
'strictKeysObject'
254-
];
256+
};
255257

256-
const _encodedAsMapKeys = ['simpleObject', 'strictKeysObject'];
258+
const _encodedAsMapKeys = {'simpleObject', 'strictKeysObject'};
257259

258-
const _iterableMapKeys = [
260+
const _iterableMapKeys = {
259261
'bigIntMap',
260262
'crazyComplex',
261263
'datetime-iterable',
@@ -280,4 +282,4 @@ const _iterableMapKeys = [
280282
'set',
281283
'stringStringMap',
282284
generatedLocalVarName,
283-
];
285+
};

json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ const invalidValueTypes = {
7070
'validatedPropertyNo42': true
7171
};
7272

73+
const disallowNullKeys = {
74+
'set',
75+
'dynamicSet',
76+
'objectSet',
77+
'intSet',
78+
'dateTimeSet',
79+
'list',
80+
'dynamicList',
81+
'objectList',
82+
'intList',
83+
'dateTimeList',
84+
'map',
85+
'stringStringMap',
86+
'dynamicIntMap',
87+
'objectDateTimeMap',
88+
'crazyComplex',
89+
generatedLocalVarName,
90+
'simpleObject',
91+
'strictKeysObject',
92+
};
93+
7394
Matcher checkedMatcher(String? expectedKey) => isA<CheckedFromJsonException>()
7495
.having((e) => e.className, 'className', 'KitchenSink')
7596
.having((e) => e.key, 'key', expectedKey);

json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ void _anyMapTests(KitchenSinkFactory factory) {
2828
for (final e in invalidValueTypes.entries) {
2929
_testBadValue(e.key, e.value, factory, false);
3030
}
31+
for (final e in disallowNullKeys) {
32+
_testBadValue(e, null, factory, false);
33+
}
3134
for (final e in _invalidCheckedValues.entries) {
3235
_testBadValue(e.key, e.value, factory, true);
3336
}
3437
});
3538
}
3639

37-
void _testBadValue(String key, Object badValue, KitchenSinkFactory factory,
40+
void _testBadValue(String key, Object? badValue, KitchenSinkFactory factory,
3841
bool checkedAssignment) {
3942
final matcher = _getMatcher(factory.checked, key, checkedAssignment);
4043

@@ -65,8 +68,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) {
6568
innerMatcher = checkedMatcher(expectedKey);
6669
} else {
6770
innerMatcher = anyOf(
68-
_isACastError,
69-
_isATypeError,
71+
isTypeError,
7072
_isAUnrecognizedKeysException(
7173
'Unrecognized keys: [invalid_key]; supported keys: '
7274
'[value, custom_field]',
@@ -86,7 +88,7 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) {
8688
break;
8789
case 'intIterable':
8890
case 'datetime-iterable':
89-
innerMatcher = _isACastError;
91+
innerMatcher = isTypeError;
9092
break;
9193
default:
9294
throw StateError('Not expected! - $expectedKey');
@@ -97,11 +99,6 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) {
9799
return throwsA(innerMatcher);
98100
}
99101

100-
final _isATypeError = isA<TypeError>();
101-
102-
// ignore: deprecated_member_use
103-
final _isACastError = isA<CastError>();
104-
105102
Matcher _isAUnrecognizedKeysException(expectedMessage) =>
106103
isA<UnrecognizedKeysException>()
107104
.having((e) => e.message, 'message', expectedMessage);

json_serializable/test/supported_types/type_test.bigint_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
test('round trip null', () {
3232
expect(
3333
() => loudEncode(SimpleClass.fromJson({})),
34-
throwsA(isA<TypeError>()),
34+
throwsTypeError,
3535
);
3636
});
3737

json_serializable/test/supported_types/type_test.bool_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
test('round trip null', () {
3232
expect(
3333
() => loudEncode(SimpleClass.fromJson({})),
34-
throwsA(isA<TypeError>()),
34+
throwsTypeError,
3535
);
3636
});
3737

json_serializable/test/supported_types/type_test.datetime_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
test('round trip null', () {
3232
expect(
3333
() => loudEncode(SimpleClass.fromJson({})),
34-
throwsA(isA<TypeError>()),
34+
throwsTypeError,
3535
);
3636
});
3737

0 commit comments

Comments
 (0)