ComeçarComece de graça

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.

Este exercício faz parte do curso

Introduction to Testing in Java

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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);
    }
}
Editar e executar o código