From 6e40b6f73b49c2652d8c043bf4fdd9fbe6fc9214 Mon Sep 17 00:00:00 2001 From: Dennis Loose Date: Tue, 12 Sep 2023 10:51:02 +0200 Subject: [PATCH] feat: add clarifying comments, clean up tests --- lib/src/packagekit/packagekit_service.dart | 6 +++- test/packagekit_service_test.dart | 37 ++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/src/packagekit/packagekit_service.dart b/lib/src/packagekit/packagekit_service.dart index 1ded8f747..97047c68a 100644 --- a/lib/src/packagekit/packagekit_service.dart +++ b/lib/src/packagekit/packagekit_service.dart @@ -19,6 +19,8 @@ class PackageKitService { bool get isAvailable => _isAvailable; bool _isAvailable = false; + // Keep track of active transactions. + // TODO: Implement `GetTransactionList` in packagekit.dart instead. int _nextId = 0; final Map _transactions = {}; @@ -49,7 +51,9 @@ class PackageKitService { try { await _client.connect(); _isAvailable = true; - } on DBusServiceUnknownException catch (_) {} + } on DBusServiceUnknownException catch (_) { + // Service isn't available + } } /// Creates a new `PackageKitTransaction` and invokes `action` on it, if diff --git a/test/packagekit_service_test.dart b/test/packagekit_service_test.dart index ba2918eb8..55dda20ea 100644 --- a/test/packagekit_service_test.dart +++ b/test/packagekit_service_test.dart @@ -10,6 +10,11 @@ import 'package:packagekit/packagekit.dart'; import 'packagekit_service_test.mocks.dart'; import 'test_utils.dart'; +const _dBusName = 'org.freedesktop.DBus'; +const _dBusInterface = 'org.freedesktop.DBus'; +const _dBusObjectPath = '/org/freedesktop/DBus'; +const _packageKitDBusName = 'org.freedesktop.PackageKit'; + void main() { group('activate service', () { test('service available', () async { @@ -19,21 +24,21 @@ void main() { expect(packageKit.isAvailable, isFalse); await packageKit.activateService(); verify(dbus.callMethod( - path: DBusObjectPath('/org/freedesktop/DBus'), - destination: 'org.freedesktop.DBus', + path: DBusObjectPath(_dBusObjectPath), + destination: _dBusName, name: 'StartServiceByName', - interface: 'org.freedesktop.DBus', - values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)], + interface: _dBusInterface, + values: const [DBusString(_packageKitDBusName), DBusUint32(0)], )).called(1); expect(packageKit.isAvailable, isTrue); await packageKit.activateService(); verifyNever(dbus.callMethod( - path: DBusObjectPath('/org/freedesktop/DBus'), - destination: 'org.freedesktop.DBus', + path: DBusObjectPath(_dBusObjectPath), + destination: _dBusName, name: 'StartServiceByName', - interface: 'org.freedesktop.DBus', - values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)], + interface: _dBusInterface, + values: const [DBusString(_packageKitDBusName), DBusUint32(0)], )); }); @@ -49,11 +54,11 @@ void main() { expect(packageKit.isAvailable, isFalse); await packageKit.activateService(); verify(dbus.callMethod( - path: DBusObjectPath('/org/freedesktop/DBus'), - destination: 'org.freedesktop.DBus', + path: DBusObjectPath(_dBusObjectPath), + destination: _dBusName, name: 'StartServiceByName', - interface: 'org.freedesktop.DBus', - values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)], + interface: _dBusInterface, + values: const [DBusString(_packageKitDBusName), DBusUint32(0)], )).called(1); expect(packageKit.isAvailable, isFalse); }); @@ -122,11 +127,11 @@ void main() { MockDBusClient createMockDbusClient() { final dbus = MockDBusClient(); when(dbus.callMethod( - path: DBusObjectPath('/org/freedesktop/DBus'), - destination: 'org.freedesktop.DBus', + path: DBusObjectPath(_dBusObjectPath), + destination: _dBusName, name: 'StartServiceByName', - interface: 'org.freedesktop.DBus', - values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)], + interface: _dBusInterface, + values: const [DBusString(_packageKitDBusName), DBusUint32(0)], )).thenAnswer((_) async => DBusMethodSuccessResponse()); return dbus; }