From 64cd59c345c5f537e98ff10899bc65222570cea1 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 27 Feb 2018 20:51:42 -0500 Subject: [PATCH] Remove unnecessary JSON calls in test --- angel_serialize_generator/test/book_test.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/angel_serialize_generator/test/book_test.dart b/angel_serialize_generator/test/book_test.dart index 8edd638f..13f0b4f9 100644 --- a/angel_serialize_generator/test/book_test.dart +++ b/angel_serialize_generator/test/book_test.dart @@ -1,9 +1,8 @@ -import 'dart:convert'; import 'package:test/test.dart'; import 'models/author.dart'; import 'models/book.dart'; -const String DEATHLY_HALLOWS_ISBN = '0-545-01022-5'; +const String deathlyHallowsIsbn = '0-545-01022-5'; main() { var deathlyHallows = new Book( @@ -22,12 +21,12 @@ main() { age: 51, books: [deathlyHallows], newestBook: deathlyHallows); - Map serializedJkRowling = JSON.decode(JSON.encode(jkRowling.toJson())); - Map deathlyHallowsMap = JSON.decode(JSON.encode(serializedDeathlyHallows)); + Map serializedJkRowling = AuthorSerializer.toMap(jkRowling); + Map deathlyHallowsMap = BookSerializer.toMap(deathlyHallows); print('J.K. Rowling: $serializedJkRowling'); - var library = new Library(collection: {DEATHLY_HALLOWS_ISBN: deathlyHallows}); - var serializedLibrary = JSON.decode(JSON.encode(library.toJson())); + var library = new Library(collection: {deathlyHallowsIsbn: deathlyHallows}); + var serializedLibrary = LibrarySerializer.toMap(library); print('Library: $serializedLibrary'); group('serialization', () { @@ -61,7 +60,7 @@ main() { test('map with @serializable class as second key is serialized', () { expect(serializedLibrary['collection'], - {DEATHLY_HALLOWS_ISBN: deathlyHallowsMap}); + {deathlyHallowsIsbn: deathlyHallowsMap}); }); }); @@ -101,8 +100,8 @@ main() { test('map with @serializable class as second key is deserialized', () { var lib = new Library.fromJson(serializedLibrary); expect(lib.collection, allOf(isNotEmpty, hasLength(1))); - expect(lib.collection.keys.first, DEATHLY_HALLOWS_ISBN); - var book = lib.collection[DEATHLY_HALLOWS_ISBN]; + expect(lib.collection.keys.first, deathlyHallowsIsbn); + var book = lib.collection[deathlyHallowsIsbn]; expect(book.id, deathlyHallows.id); expect(book.author, deathlyHallows.author); expect(book.description, deathlyHallows.description);