diff --git a/test/local_storage_manager/local_storage_manager_test.dart b/test/local_storage_manager/local_storage_manager_test.dart index 123f8da..005cdd1 100644 --- a/test/local_storage_manager/local_storage_manager_test.dart +++ b/test/local_storage_manager/local_storage_manager_test.dart @@ -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'; @@ -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'; @@ -132,4 +132,23 @@ void main() { throwsA(isA()), ); }); + + 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>( + fileName: fileName, + localStoragePath: localStoragePath, + fromJson: (json) => json, + ), + throwsA(isA()), + ); + }); }