Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago