Garmaine Staff asked 4 months ago

Please help me. I am trying to run a unit test in a Java code (simple code I am running as part of Java trainning), but I don't manage to import the packages related to the annotation "@Test" and method "equalTo()" in AccountTest class (see the code below).

Here is the setup information:

  • I have tried to run this code using IDE's "Eclipse Java Oxygen" and "Eclipse IDE for Java Developers – 2020-03";
  • I have updated the JDK to version 13 (I have updated PATH system variable adding the file directory "C:\Program Files\Java\jdk-13.0.2\bin");
  • I am using JRE 1.8.0_241;
  • OS: Windows 7 Professional;

Code of Unit Test (here is the problem), AccountTest class:

public class AccountTest {

    @Test // Eclipse error reported: "Test cannot be resolved to a type". It does not offer to import the package related to the annotation "@Test"
    public void onWithdrawalBalanceShouldBeReduced() {
        Account account = new Account(200d);
        account.withdraw(50d);

        assertThat(account.getBalance(), is(equalTo(150d))); // Eclipse error reported: "The method equalTo(Double) is undefined for the type AccountTest". It does not offer to import the package related to method "equalTo()"
    }
}

Code for Account Class:

public class Account {

    private double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    public void withdraw(double value) {
        this.balance = this.balance + value;
    }

    public void deposit(double valor) {
        this.balance = this.balance + valor;
    }

    public void setBalance(double saldo) {
        this.balance = saldo;
    }

    public double getBalance() {
        return balance;
    }
}

Code for Bank Class:

public class Bank {

    public void deposit(Account account, double value) {
        account.deposit(value);
    }

    public void doTranference(Account account1, double value, Account account2) {
        account1.withdraw(value);
        account2.deposit(value);
    }
}