Skip to content

Commit 37e58f6

Browse files
test(policy_manager): update error handling to use PolicySDKException in integration tests
1 parent fa55733 commit 37e58f6

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

test/core/integration_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import 'package:flutter_policy_engine/flutter_policy_engine.dart';
12
import 'package:flutter_test/flutter_test.dart';
23
import 'package:flutter_policy_engine/src/core/policy_manager.dart';
34
import 'package:flutter_policy_engine/src/core/memory_policy_storage.dart';
45
import 'package:flutter_policy_engine/src/core/role_evaluator.dart';
6+
import 'package:flutter_policy_engine/src/exceptions/policy_sdk_exception.dart';
57

68
void main() {
79
group('Core Integration Tests', () {
@@ -169,7 +171,7 @@ void main() {
169171

170172
// Should throw when storage fails
171173
expect(() => failingManager.initialize(jsonPolicies),
172-
throwsA(isA<StateError>()));
174+
throwsA(isA<PolicySDKException>()));
173175
expect(failingManager.isInitialized, isFalse);
174176
});
175177

test/core/policy_manager_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void main() {
207207
};
208208

209209
expect(() => policyManager.initialize(jsonPolicies),
210-
throwsA(isA<StateError>()));
210+
throwsA(isA<PolicySDKException>()));
211211
expect(policyManager.isInitialized, isFalse);
212212
});
213213

@@ -343,7 +343,7 @@ void main() {
343343
mockStorage.setShouldThrowOnSave(true);
344344

345345
expect(() => policyManager.initialize(jsonPolicies),
346-
throwsA(isA<StateError>()));
346+
throwsA(isA<PolicySDKException>()));
347347
expect(policyManager.isInitialized, isFalse);
348348
});
349349

@@ -425,7 +425,7 @@ void main() {
425425

426426
expect(
427427
() => policyManager.initialize(jsonPolicies),
428-
throwsA(isA<StateError>()),
428+
throwsA(isA<PolicySDKException>()),
429429
);
430430

431431
expect(policyManager.isInitialized, isFalse);
@@ -444,7 +444,7 @@ void main() {
444444

445445
expect(
446446
() => policyManager.initialize(jsonPolicies),
447-
throwsA(isA<StateError>()),
447+
throwsA(isA<PolicySDKException>()),
448448
);
449449
});
450450
});
@@ -931,11 +931,14 @@ void main() {
931931
// Make storage throw on save
932932
mockStorage.setShouldThrowOnSave(true);
933933

934-
// The method catches exceptions and doesn't rethrow them
935-
await policyManager
936-
.initializeFromJsonAssets('assets/policies/test.json');
934+
// The method should throw PolicySDKException when storage fails
935+
expect(
936+
() => policyManager
937+
.initializeFromJsonAssets('assets/policies/test.json'),
938+
throwsA(isA<PolicySDKException>()),
939+
);
937940

938-
// Should handle gracefully and not initialize due to storage error
941+
// Should not be initialized due to storage error
939942
expect(policyManager.isInitialized, isFalse);
940943

941944
// Clean up mock message handler

0 commit comments

Comments
 (0)