Browse Source

Merge pull request #756 from nextcloud/test/dynamite_runtime/content_string

test(dynamite_runtime): test serialization failure
pull/757/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
bebabc34d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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>) { 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.'); 'Please ensure the StandardJsonPlugin is applied and run before.');
} }
@ -44,7 +44,7 @@ class ContentStringPlugin implements SerializerPlugin {
} }
if (object is! String) { 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.'); '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(); .build();
final Serializers invalidSerializers = (_$serializers.toBuilder()
..addPlugin(const ContentStringPlugin())
..addBuilderFactory(const FullType(ContentString, [FullType(bool)]), ContentStringBuilder<bool>.new))
.build();
void main() { void main() {
group('ContentString with known specifiedType holding bool', () { group('ContentString with known specifiedType holding bool', () {
final data = ContentString<bool>((final b) => b..content = true); final data = ContentString<bool>((final b) => b..content = true);
@ -310,4 +315,21 @@ void main() {
expect(serializers.deserialize(serialized, specifiedType: specifiedType), data); 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