Last active
March 17, 2022 06:35
-
-
Save Bharathh-Raj/421b320016658c4c86b662284aaa7795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Note: This code is just for demonstration purpose | |
class MockRemoteDateSourceSuccess extends DataSource { | |
@override | |
Future<String> fetch() async { | |
return Future.value("Mock Result"); | |
} | |
} | |
class MockRemoteDateSourceFailure extends DataSource { | |
@override | |
Future<String> fetch() async { | |
throw SocketException("Mock exception"); | |
} | |
} | |
void main(){ | |
test("fetch() should return an instance of student on remoteDataSource's fetch success", () { | |
Repository repo = Repository(MockRemoteDateSourceSuccess()); | |
final result = repo.fetch(); | |
expect(result, isInstanceOf<Student>()); | |
}); | |
test("fetch() should throw an exception on remoteDataSource's fetch throws any exception", () { | |
Repository repo = Repository(MockRemoteDateSourceFailure()); | |
expect(() => repo.fetch(), throwsException); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment