Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,18 @@ class PackageInfo {
String toString() {
return 'PackageInfo(appName: $appName, buildNumber: $buildNumber, packageName: $packageName, version: $version, buildSignature: $buildSignature, installerStore: $installerStore)';
}

Map<String, dynamic> _toMap() {
return {
'appName': appName,
'buildNumber': buildNumber,
'packageName': packageName,
'version': version,
if (buildSignature.isNotEmpty) 'buildSignature': buildSignature,
if (installerStore?.isNotEmpty ?? false) 'installerStore': installerStore,
};
}

/// Gets a map representation of the [PackageInfo] instance.
Map<String, dynamic> get data => _toMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,51 +75,91 @@ void main() {

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);
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);
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);
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);
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);
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)',
);
});

test('data returns a map representation', () async {
PackageInfo.setMockInitialValues(
appName: 'mock_package_info_example',
packageName: 'io.flutter.plugins.mockpackageinfoexample',
version: '1.1',
buildNumber: '2',
buildSignature: '',
installerStore: null,
);
final info1 = await PackageInfo.fromPlatform();
expect(info1.data, {
'appName': 'mock_package_info_example',
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
'version': '1.1',
'buildNumber': '2',
});
PackageInfo.setMockInitialValues(
appName: 'mock_package_info_example',
packageName: 'io.flutter.plugins.mockpackageinfoexample',
version: '1.1',
buildNumber: '2',
buildSignature: 'deadbeef',
installerStore: 'testflight',
);
final info2 = await PackageInfo.fromPlatform();
expect(info2.data, {
'appName': 'mock_package_info_example',
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
'version': '1.1',
'buildNumber': '2',
'buildSignature': 'deadbeef',
'installerStore': 'testflight',
});
});
}