Question: These are my two classes of java (ECLIPSE) and they are part of the same project. I'm having an assertion failure in junit . As

These are my two classes of java (ECLIPSE) and they are part of the same project. I'm having an assertion failure in junit . As its a failure it means one of my assumption is wrong here... I cant figure out which one... I'm attaching the failure screenshot.

These are my two classes of java (ECLIPSE) and they are part

public class Money { private int cAmount; private String cCurrency; // constructor for creating a money object public Money(int amount, String currency) { cAmount = amount; cCurrency = currency; }

// set money public int getAmount() { return cAmount; }

// get money public String getCurrency() { return cCurrency; }

public Money add(Money m) throws Exception { if (m.getAmount()

@Override public boolean equals(Object anObject) { if (anObject instanceof Money) { Money passedMoney = (Money) anObject; if (this.cAmount == passedMoney.getAmount() && this.cCurrency.equals(passedMoney.getCurrency())) return true; } return false; } }

second code:

import org.junit.Test; import static org.junit.Assert.*;

public class MoneyTest {

//Testing that two Money objects are successfully added together @Test (expected = Exception.class) public void simpleAdd() throws Exception { Money m12CAD= new Money(12, "CAD"); Money m14CAD= new Money(14, "CAD"); Money known= new Money(26, "CAD"); Money observed= m12CAD.add(m14CAD); assertTrue(known.equals(observed)); }

//testing that exception is thrown correctly @Test (expected = Exception.class) public void testNegativeMoneyValue () throws Exception{ Money m12CAD= new Money(12, "CAD"); Money m14CAD= new Money(-14, "CAD"); Money known= new Money(26, "CAD"); Money observed= m12CAD.add(m14CAD); assertTrue(known.equals(observed)); } @Test (expected = Exception.class) public void simpleAddFailure() throws Exception { Money m12CAD= new Money(12, "CAD"); Money m14CAD= new Money(-14, "CAD"); Money known= new Money(26, "CAD"); Money observed= m12CAD.add(m14CAD); assertTrue(known.equals(observed)); } }

Finished arter 0.037 seconds Runs: 3/3 * Errors: 1 Failures: 0 E MoneyTest (Runner: JUnit 4] (0.0145) simpleAdd(0.011 s) testNegativeMoneyValue (0.000 s) simpleAddFailure (0.002 s) = Failure Trace J! java.lang.Exception: Unexpected exception, expected but was

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!