response_serialization_test.dart 1.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';

import 'package:integration_test/common.dart';

void main() {
  test('Serialize and deserialize Failure', () {
    final Failure fail = Failure('what a name', 'no detail');
    final Failure restored = Failure.fromJsonString(fail.toString());
    expect(restored.methodName, fail.methodName);
    expect(restored.details, fail.details);
  });

  test('Serialize and deserialize Response', () {
    Response response, restored;
    String jsonString;

    response = Response.allTestsPassed();
    jsonString = response.toJson();
    expect(jsonString, '{"result":"true","failureDetails":[]}');
    restored = Response.fromJson(jsonString);
    expect(restored.allTestsPassed, response.allTestsPassed);
    expect(restored.data, null);
    expect(restored.formattedFailureDetails, '');

    final Failure fail = Failure('what a name', 'no detail');
    final Failure fail2 = Failure('what a name2', 'no detail2');
    response = Response.someTestsFailed(<Failure>[fail, fail2]);
    jsonString = response.toJson();
    restored = Response.fromJson(jsonString);
    expect(restored.allTestsPassed, response.allTestsPassed);
    expect(restored.data, null);
    expect(restored.formattedFailureDetails, response.formattedFailureDetails);

    final Map<String, dynamic> data = <String, dynamic>{'aaa': 'bbb'};
    response = Response.allTestsPassed(data: data);
    jsonString = response.toJson();
    restored = Response.fromJson(jsonString);
42 43
    expect(restored.data!.keys, <String>['aaa']);
    expect(restored.data!.values, <String>['bbb']);
44 45 46 47

    response = Response.someTestsFailed(<Failure>[fail, fail2], data: data);
    jsonString = response.toJson();
    restored = Response.fromJson(jsonString);
48 49
    expect(restored.data!.keys, <String>['aaa']);
    expect(restored.data!.values, <String>['bbb']);
50 51
  });
}