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.
Diese Übung ist Teil des Kurses
Introduction to Testing in Java
Anleitung zur Übung
- Fill in the correct assertion to verify the exception is an instance of
RuntimeException. - Use the correct assertion to check equality.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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());
}
}