Remove unnecessary JSON calls in test

This commit is contained in:
Tobe O 2018-02-27 20:51:42 -05:00
parent ea298d4362
commit 64cd59c345

View file

@ -1,9 +1,8 @@
import 'dart:convert';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'models/author.dart'; import 'models/author.dart';
import 'models/book.dart'; import 'models/book.dart';
const String DEATHLY_HALLOWS_ISBN = '0-545-01022-5'; const String deathlyHallowsIsbn = '0-545-01022-5';
main() { main() {
var deathlyHallows = new Book( var deathlyHallows = new Book(
@ -22,12 +21,12 @@ main() {
age: 51, age: 51,
books: [deathlyHallows], books: [deathlyHallows],
newestBook: deathlyHallows); newestBook: deathlyHallows);
Map serializedJkRowling = JSON.decode(JSON.encode(jkRowling.toJson())); Map serializedJkRowling = AuthorSerializer.toMap(jkRowling);
Map deathlyHallowsMap = JSON.decode(JSON.encode(serializedDeathlyHallows)); Map deathlyHallowsMap = BookSerializer.toMap(deathlyHallows);
print('J.K. Rowling: $serializedJkRowling'); print('J.K. Rowling: $serializedJkRowling');
var library = new Library(collection: {DEATHLY_HALLOWS_ISBN: deathlyHallows}); var library = new Library(collection: {deathlyHallowsIsbn: deathlyHallows});
var serializedLibrary = JSON.decode(JSON.encode(library.toJson())); var serializedLibrary = LibrarySerializer.toMap(library);
print('Library: $serializedLibrary'); print('Library: $serializedLibrary');
group('serialization', () { group('serialization', () {
@ -61,7 +60,7 @@ main() {
test('map with @serializable class as second key is serialized', () { test('map with @serializable class as second key is serialized', () {
expect(serializedLibrary['collection'], expect(serializedLibrary['collection'],
{DEATHLY_HALLOWS_ISBN: deathlyHallowsMap}); {deathlyHallowsIsbn: deathlyHallowsMap});
}); });
}); });
@ -101,8 +100,8 @@ main() {
test('map with @serializable class as second key is deserialized', () { test('map with @serializable class as second key is deserialized', () {
var lib = new Library.fromJson(serializedLibrary); var lib = new Library.fromJson(serializedLibrary);
expect(lib.collection, allOf(isNotEmpty, hasLength(1))); expect(lib.collection, allOf(isNotEmpty, hasLength(1)));
expect(lib.collection.keys.first, DEATHLY_HALLOWS_ISBN); expect(lib.collection.keys.first, deathlyHallowsIsbn);
var book = lib.collection[DEATHLY_HALLOWS_ISBN]; var book = lib.collection[deathlyHallowsIsbn];
expect(book.id, deathlyHallows.id); expect(book.id, deathlyHallows.id);
expect(book.author, deathlyHallows.author); expect(book.author, deathlyHallows.author);
expect(book.description, deathlyHallows.description); expect(book.description, deathlyHallows.description);