// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'dart:convert'; import 'package:test/test.dart'; import '../test_utils.dart'; import 'generic_class.dart'; void main() { group('generic', () { GenericClass roundTripGenericClass( GenericClass p) { final outputJson = loudEncode(p); final p2 = GenericClass.fromJson( jsonDecode(outputJson) as Map); final outputJson2 = loudEncode(p2); expect(outputJson2, outputJson); return p2; } test('no type args', () { roundTripGenericClass(GenericClass() ..fieldDynamic = 1 ..fieldInt = 2 ..fieldObject = 3 ..fieldT = 5 ..fieldS = 'six'); }); test('with type arguments', () { roundTripGenericClass(GenericClass() ..fieldDynamic = 1 ..fieldInt = 2 ..fieldObject = 3 ..fieldT = 5.0 ..fieldS = 'six'); }); test('with bad arguments', () { expect( () => GenericClass() ..fieldT = (true as dynamic) as double, throwsCastError); }); test('with bad arguments', () { expect( () => GenericClass()..fieldS = (5 as dynamic) as String, throwsCastError); }); }); }