Skip to content

Commit

Permalink
test: add missing test case and reformulate cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hampuslavin committed Dec 9, 2024
1 parent f15aa06 commit e472ddc
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/local_storage_manager/local_storage_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void main() {
});

test(
'Given a json serialization error '
'Given a json object with non compatible values '
'when calling storeJsonFile '
'then it throws SerializationException', () async {
var fileName = 'test.json';
Expand Down Expand Up @@ -114,7 +114,7 @@ void main() {
});

test(
'Given a json deserialization error '
'Given a malformed json file '
'when calling tryFetchAndDeserializeJsonFile '
'then it throws DeserializationException', () async {
var fileName = 'invalid.json';
Expand All @@ -132,4 +132,23 @@ void main() {
throwsA(isA<DeserializationException>()),
);
});

test(
'Given a corrupt file '
'when calling tryFetchAndDeserializeJsonFile '
'then it throws ReadException', () async {
var fileName = 'invalid.json';
var file = File(p.join(localStoragePath, fileName));
file.writeAsBytesSync([0xC3, 0x28]);

expect(
() => LocalStorageManager.tryFetchAndDeserializeJsonFile<
Map<String, dynamic>>(
fileName: fileName,
localStoragePath: localStoragePath,
fromJson: (json) => json,
),
throwsA(isA<ReadException>()),
);
});
}

0 comments on commit e472ddc

Please sign in to comment.