Get startedGet started for free

Foreign exchange

The European Central Bank provides reference daily exchange rates for currencies against the Euro. They update every working day at 16:00 CET. For this exercise, EuropeanCentralBankServer uses preloaded reference rates for October 2025.

Here is one of them: the rate for EUR to TRY (Turkish Lira) together with its fluctuations over the past year. Consider the graph in the link. Can you bet on what tomorrow's rate will be?

Complete the integration test asserting some basic properties of the currency conversion.

This exercise is part of the course

Introduction to Testing in Java

View Course

Exercise instructions

  • Create a new EuropeanCentralBankServer object (not a mock).
  • As ExhangeApp depends on EuropeanCentralBankServer, use your new object to create an ExchangeApp
  • Make a meaningful assertion on the value of the converted amount that verifies the exchange works as intended.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

class Main {
    public static void main(String[] args) {
        launchTestsAndPrint(ExchangeAppTest.class);
    }
}

class ExchangeAppTest {

    @Test
    void convertEuroTo_convertsTRY() {
        // Create a EuropeanCentralBankServer object
        EuropeanCentralBankServer bank = ____; 
        // Pass the dependency to the constructor of ExchangeApp
        ExchangeApp exchangeApp = ____;
        double euroAmount = 100;
        double tryAmount = exchangeApp.convertEuroTo("TRY", euroAmount);
        System.out.println("Converted " + euroAmount + " EUR to " + tryAmount + " TRY.");
        // Write down a meaningful assertion that matches the expression in the parentheses
        ____(tryAmount > 0);
    }
}
Edit and Run Code