1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Java

Connected

Exercise

Unit test: Foreign exchange exceptions

One possible error scenario for the exchange app is the bank server being unavailable due to an outage or network issues. To ensure against disruptive exceptions, you have coded in a try/catch inside the convertEuroTo method.

Simulate the error scenario by making the mock EuropeanCentralBankServer object throw an exception when a rate is requested.

Instructions

100 XP
  • Make the mock bank object throw an exception when getRateEuroTo is called.
  • Create the exact exception object you want to simulate.
  • Verify the convertEuroTo method does not throw an exception but returns -1 in this scenario.