CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Introduction to Testing in Java

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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);
    }
}
Modifier et exécuter le code