Skip to content

Commit

Permalink
Added testcases for using vendor specific types with the factory regi…
Browse files Browse the repository at this point in the history
…stries
  • Loading branch information
joanne-ter-maat authored and ricardoboss committed Oct 17, 2024
1 parent b4f9614 commit a192983
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:convert';

import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'parse_node_factory_registry_test.mocks.dart';

@GenerateMocks([ParseNodeFactory, ParseNode])
void main() {
group('ParseNodeFactoryRegistry', () {
test('VendorSpecificContentType', () {
const contentType = 'application/json';
final mockFactory = MockParseNodeFactory();
final jsonStream= utf8.encode('{"test": "input"}');
final mockParseNode = MockParseNode();
when(mockFactory.getRootParseNode(contentType, jsonStream)).thenReturn(mockParseNode);
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.putIfAbsent(contentType, ()=>mockFactory);
final rootParseNode = ParseNodeFactoryRegistry.defaultInstance.getRootParseNode('application/vnd+json', jsonStream);
expect(rootParseNode, isNotNull);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'serialization_writer_factory_registry_test.mocks.dart';

@GenerateMocks([SerializationWriter, SerializationWriterFactory])
void main() {
group('SerializationWriterFactoryRegistry', () {
test('VendorSpecificContentType', () {
const contentType = 'application/text';
final mockWriter = MockSerializationWriter();
final mockFactory = MockSerializationWriterFactory();
when(mockFactory.getSerializationWriter(contentType)).thenReturn(mockWriter);
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.putIfAbsent(contentType, () => mockFactory);
final serializationWriter = SerializationWriterFactoryRegistry.defaultInstance.getSerializationWriter('application/vnd+text');
expect(serializationWriter, isNotNull);
});
});
}

0 comments on commit a192983

Please sign in to comment.