Foreign Exchange: Error scenario
The documentation for the EuropeanCentralBankServer library says that attempting to convert to currencies the bank
doesn't offer will result in this exception:
new RuntimeException("Currency not in ECB list: " + currencyName)
Write an integration test that verifies this error scenario.
Este ejercicio forma parte del curso
Introduction to Testing in Java
Instrucciones del ejercicio
- Fill in the correct assertion to verify the exception is an instance of
RuntimeException. - Use the correct assertion to check equality.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
class Main {
public static void main(String[] args) {
launchTestsAndPrint(ExchangeAppTest.class);
}
}
class ExchangeAppTest {
@Test
void convert_throwsException_whenGetRateThrowsException() {
EuropeanCentralBankServer bank = new EuropeanCentralBankServer();
ExchangeApp exchangeApp = new ExchangeApp(bank);
Exception expectedException = null;
try {
double result = exchangeApp.convertEuroTo("Invalid Currency", 1000);
} catch (Exception e) {
expectedException = e;
}
// Assert that the exception is an instance of the correct class
____(RuntimeException.class, expectedException);
// Assert that the exception message is correct
____("Currency not in ECB list: Invalid Currency", expectedException.getMessage());
}
}