forked from fluttercommunity/plus_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_info_test.dart
121 lines (111 loc) · 3.77 KB
/
package_info_test.dart
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2019 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/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:package_info_plus/package_info_plus.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('dev.fluttercommunity.plus/package_info');
final log = <MethodCall>[];
channel.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
case 'getAll':
return <String, dynamic>{
'appName': 'package_info_example',
'buildNumber': '1',
'packageName': 'io.flutter.plugins.packageinfoexample',
'version': '1.0',
'installerStore': null,
};
default:
assert(false);
return null;
}
});
tearDown(() {
log.clear();
});
test('fromPlatform', () async {
final info = await PackageInfo.fromPlatform();
expect(info.appName, 'package_info_example');
expect(info.buildNumber, '1');
expect(info.packageName, 'io.flutter.plugins.packageinfoexample');
expect(info.version, '1.0');
expect(info.installerStore, null);
expect(
log,
<Matcher>[
isMethodCall('getAll', arguments: null),
],
);
}, onPlatform: {
'linux':
const Skip('PackageInfoPlus on Linux does not use platform channels'),
});
test('Mock initial values', () async {
PackageInfo.setMockInitialValues(
appName: 'mock_package_info_example',
packageName: 'io.flutter.plugins.mockpackageinfoexample',
version: '1.1',
buildNumber: '2',
buildSignature: 'deadbeef',
installerStore: null,
);
final info = await PackageInfo.fromPlatform();
expect(info.appName, 'mock_package_info_example');
expect(info.buildNumber, '2');
expect(info.packageName, 'io.flutter.plugins.mockpackageinfoexample');
expect(info.version, '1.1');
expect(info.buildSignature, 'deadbeef');
expect(info.installerStore, null);
});
test('equals checks for value equality', () async {
final info1 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
final info2 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(info1, info2);
});
test('hashCode checks for value equality', () async {
final info1 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
final info2 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(info1.hashCode, info2.hashCode);
});
test('toString returns a string representation', () async {
final info = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(
info.toString(),
'PackageInfo(appName: package_info_example, buildNumber: 1, packageName: io.flutter.plugins.packageinfoexample, version: 1.0, buildSignature: , installerStore: null)',
);
});
}