Q:

JUnit Testing: It throws 2 exceptions

Here is my class that needed to test:
package testing;

public class Money {

    private int Amount;
    private String Currency;

    public int getAmount(){return Amount;}

    public String getCurrency(){return Currency;}

    public Money(int amount, String currency){
        Amount= amount;
        Currency= currency;
        }

    public Money addMoney(Money m){

        return (new Money(getAmount()+m.getAmount(),getCurrency()));
    }

here is my JUnit test class 
package testing;

import static org.junit.Assert.*;

import org.junit.Test;

public class MoneyTest {

    @Test
    public void testAddMoney() {
        Money m1 = new Money (20,"DH");
        Money m2 = new Money(10,"DH");
        Money expected = new Money(30,"DH");
        Money result = m1.addMoney(m2);
        assertTrue(result.equals(expected));
    }

    @Test
    public void testEquals(){
        Money m1 = new Money (20,"DH");
        Money m2 = new Money(10,"DH");

        assertTrue(!(m1.equals(null)));
        assertEquals(m1, m1);
        assertEquals(m1, new Money(20,"DH"));
        assertTrue(!m1.equals(m2));

    }

When I run the test, it throws the first exception:
 java.lang.AssertionError 
at testing.MoneyTest.testAddMoney(MoneyTest.jaba:15)15 is the number of line : assertTrue(result.equals(expected));

and second one : 
java.lang.AssertionError at testing.MoneyTest.testEquals(MoneyTest.java:26) 26 is the number of line: assertEquals(m1, new Money(20,"DH"));

What is the problem ???     

A:

You Money class didn't override equals method, so
assertTrue(result.equals(expected));

Use equals method from Object class, and 2 instances are not equals.
Either override equals method on your Money class, or change the test
assertEquals(expected.getAmount(), result.getAmount());

