Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEnyang Mercy
Courses Plus Student 2,339 PointsUnit Testing in java CreditorTest make a new test using tripple A
I don't understand what exactly is required. Can someone explain with details. Thank you
package com.teamtreehouse.vending;
import org.junit.Test;
import static org.junit.Assert.*;
public class CreditorTest {
@Test
public void addingFundsIncrementsAvailableFunds() throws Exception {
Creditor creditor = new Creditor();
creditor.addFunds(25);
creditor.addFunds(25);
assertEquals(50, creditor.getAvailableFunds());
}
@Test
public void refundingReturnsAllAvailableFunds() throws Exception {
Creditor creditor = new Creditor();
creditor.addFunds(10);
int refund = creditor.refund();
assertEquals(10, refund);
assertEquals(0, creditor.getAvailableFunds());
}
}
package com.teamtreehouse.vending;
public class Creditor {
private int funds;
public Creditor() {
funds = 0;
}
public void addFunds(int money) {
funds += money;
}
public void deduct(int money) throws NotEnoughFundsException {
if (money > funds) {
throw new NotEnoughFundsException();
}
funds -= money;
}
public int refund() {
int refund = funds;
funds = 0;
return refund;
}
public int getAvailableFunds() {
return funds;
}
}
1 Answer
Yanuar Prakoso
15,196 PointsHi There
As you see in this section of your code:
@Test
public void refundingReturnsAllAvailableFunds() throws Exception {
//This is Arrange:
Creditor creditor = new Creditor();
creditor.addFunds(10);
//This is action
int refund = creditor.refund();
//This is asserts:
assertEquals(10, refund);
assertEquals(0, creditor.getAvailableFunds());
}
There are two asserts in the refundingReturnsAllAvailableFunds() Test. You need to make one more Test method called refundingResetsAvailableFundsToZero() and move one of the Asserts into this new Test. You can guess which Assert needs to move from the name of the test, right? Here is how I build the other test:
@Test
public void refundingResetsAvailableFundsToZero() throws Exception {
//This is Arrange:
Creditor creditor = new Creditor();
creditor.addFunds(10);
//This is Act:
int refund = creditor.refund();
//This is Asserts:
assertEquals(0, creditor.getAvailableFunds());
}
I hope this can help a little