This file contains hidden or 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 FetchLoanDetail extends UseCase<LoanParamRequest, LoanDetailResponse> { | |
final ILoanRepository _loanRepository; | |
FetchLoanDetail(this._loanRepository); | |
@override | |
Stream<LoanDetailResponse> buildUseCase(LoanParamRequest param) { | |
return _loanRepository | |
.getLoanFromServer(param.amount, param.time) | |
.asStream() |
This file contains hidden or 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
test( | |
"Fetch loan should not fail with any exception when mocked with success response", | |
() { | |
FetchLoanDetail fetchLoanUseCase = | |
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO(3))); | |
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) { | |
}, expectAsync1((error) { | |
expect(error, isNot(isInstanceOf<UseCaseNotImplementedException>()), |
This file contains hidden or 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 MockedSucessRateFetchRepository extends ILoanRepository { | |
final LoanDetailDTO _mockedResponse; | |
MockedSucessRateFetchRepository(this._mockedResponse); | |
Future<LoanDetailDTO> getLoanFromServer(double amount, double time) { | |
return Future.value(this._mockedResponse); | |
} | |
} |
This file contains hidden or 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 LoanParamRequest { | |
final double amount, time; | |
LoanParamRequest(this.amount, this.time); | |
} | |
class LoanDetailResponse { | |
String? _emi; | |
} |
This file contains hidden or 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 EMICalculator { | |
final double amount, rate, time; | |
EMICalculator(this.amount, this.rate, this.time); | |
double calculateEMI() | |
{ | |
return amount*rate*(1 + rate)*time/((1+rate)*time-1); | |
} | |
} |
This file contains hidden or 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() | |
{ | |
test("EMI cannot be zero",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.calculateEMI(),greaterThan(0),reason:"EMI calculated is zero"); | |
}); | |
} |
This file contains hidden or 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
//Domain Entity responsible for calculating EMI for given params. | |
class EMICalculator { | |
final double amount, rate, time; | |
EMICalculator(this.amount, this.rate, this.time); | |
double calculateEMI() | |
{ | |
return -1; | |
} |
This file contains hidden or 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() | |
{ | |
test("Amount cannot be null",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.amount,isNot(null), reason:"Amount cannot be null"); | |
}); |
This file contains hidden or 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
//Domain Entity responsible for calculating EMI for given params. | |
class EMICalculator { | |
final double amount, rate, time; | |
EMICalculator(this.amount, this.rate, this.time); | |
} |
This file contains hidden or 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() | |
{ | |
test("Amount cannot be null",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(); | |
//Performing assertion | |
expect(emiCalculator.amount,isNot(null), reason:"Amount cannot be null"); | |
}); |