Browse Source

test(dynamite_runtime): test serialization failure

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/756/head
Nikolas Rimikis 1 year ago
parent
commit
aacefd312c
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 4
      packages/dynamite/dynamite_runtime/lib/src/content_string.dart
  2. 22
      packages/dynamite/dynamite_runtime/test/content_string_test.dart

4
packages/dynamite/dynamite_runtime/lib/src/content_string.dart

@ -28,7 +28,7 @@ class ContentStringPlugin implements SerializerPlugin {
}
if (object is! Map<String, dynamic>) {
throw ArgumentError('ContentStringPlugin can only be applied to Map<String, dynamic>. '
throw StateError('ContentStringPlugin can only be applied to Map<String, dynamic>. '
'Please ensure the StandardJsonPlugin is applied and run before.');
}
@ -44,7 +44,7 @@ class ContentStringPlugin implements SerializerPlugin {
}
if (object is! String) {
throw ArgumentError('The serialized ContentString must be of type String. '
throw StateError('The serialized ContentString must be of type String. '
'Please ensure the StandardJsonPlugin is applied and run before.');
}

22
packages/dynamite/dynamite_runtime/test/content_string_test.dart

@ -42,6 +42,11 @@ final Serializers serializers = (_$serializers.toBuilder()
))
.build();
final Serializers invalidSerializers = (_$serializers.toBuilder()
..addPlugin(const ContentStringPlugin())
..addBuilderFactory(const FullType(ContentString, [FullType(bool)]), ContentStringBuilder<bool>.new))
.build();
void main() {
group('ContentString with known specifiedType holding bool', () {
final data = ContentString<bool>((final b) => b..content = true);
@ -310,4 +315,21 @@ void main() {
expect(serializers.deserialize(serialized, specifiedType: specifiedType), data);
});
});
group('Serialize without registered StandardJsonPlugin', () {
final data = ContentString<bool>((final b) => b..content = true);
const serialized = true;
const specifiedType = FullType(ContentString, [FullType(bool)]);
test('serialization error', () {
expect(() => invalidSerializers.serialize(data, specifiedType: specifiedType), throwsA(isA<StateError>()));
});
test('deserialization error', () {
expect(
() => invalidSerializers.deserialize(serialized, specifiedType: specifiedType),
throwsA(isA<StateError>()),
);
});
});
}

Loading…
Cancel
Save