Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Testing in Java

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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

class ExchangeAppTest {

    @Test
    void convertEuroTo_convertsTRY() {
        // Create a EuropeanCentralBankServer object
        EuropeanCentralBankServer bank = new ____(); 
        // Pass the dependency to the constructor of ExchangeApp
        ExchangeApp exchangeApp = new ____(____);
        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);
    }
}
Code bewerken en uitvoeren