ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Introduction to Testing in Java

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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);
    }
}
Editar y ejecutar código