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
class InstagramPost { | |
final String username; | |
final String userProfilePicUrl; | |
final String postId; | |
final String imageUrl; | |
final String caption; | |
final int likes; | |
final List<Comment> comments; | |
final DateTime timestamp; |
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
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override |
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
void main(){ | |
Wallet btc = BTCWallet(BTCWalletDC("", 0)); | |
btc.derive(); | |
btc.walletDC.balance; | |
} | |
// @freezed | |
// class WalletDC with _$WalletDC { | |
// const factory WalletDC.eth(String phrase, double balance) = ETHWalletDC; | |
// const factory WalletDC.btc(String phrase, double balance) = BTCWalletDC; |
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
class MockRemoteDataSource extends Mock implements RemoteDateSource{} | |
void main(){ | |
test("fetch() should return an instance of student on remoteDataSource's fetch success", () { | |
//Arrange | |
MockRemoteDateSource mockDS = MockRemoteDateSource(); | |
Repository repo = Repository(mockDS); | |
when(mockDS.fetch()).thenReturn("Mock Result"); | |
//Act | |
final result = repo.fetch(); |
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
import 'package:mockito/annotations.dart'; | |
import 'package:mockito/mockito.dart'; | |
import 'repository_test.mocks.dart'; // Don't forget to include this | |
@GenerateMocks([RemoteDateSource]) | |
void main() { | |
test("fetch() should return an instance of student on remoteDataSource's fetch success", () { | |
//Arrange | |
MockRemoteDateSource mockDS = MockRemoteDateSource(); | |
Repository repo = Repository(mockDS); |
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 { |
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
abstract class DataSource { | |
Future<String> fetch(); | |
} | |
class RemoteDateSource extends DataSource { | |
@override | |
Future<String> fetch() async { | |
final result = await httpClient.get("", 0, ""); | |
return result; | |
} |
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 | |
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", () { |
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 implements RemoteDateSource { | |
@override | |
Future<String> fetch() async { | |
return Future.value("Mock Result"); | |
} | |
} | |
class MockRemoteDateSourceFailure implements RemoteDateSource { |
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 Repository { | |
final RemoteDateSource remoteDateSource; | |
Repository(this.remoteDateSource); | |
Future<Student> fetch() async { | |
late String result; | |
try { | |
result = await remoteDateSource.fetch(); |
NewerOlder