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 trialBrandon Johnson
900 Pointssorry Im confused about the whole thing.......I dont even know where Im at Oh **** I need help please
just explain to me whats going on......tell me whats whats
package com.teamtreehouse.vending;
import org.junit.Test;
import static org.junit.Assert.*;
public class CreditorTest {
@Test
public void addingFundsIncrementsAvailableFunds(0) throws Exception {
Creditor creditor = new Creditor();
creditor.addFunds(25);
creditor.addFunds(25);
assertEquals(50, creditor.getAvailableFunds(0));
}
@Test
public void refundingReturnsAllAvailableFunds(0) throws Exception {
Creditor creditor = new Creditor();
creditor.addFunds(10);
int refund = creditor.refund(10);
assertEquals(10, refund);
assertEquals(0, creditor.getAvailableFunds());
}
}
package com.teamtreehouse.vending;
public class Creditor {
private int funds;
public Creditor(0) {
funds = 0;
}
public void addFunds(int money) {
funds += money;
}
public void deduct(int money) throws NotEnoughFundsException {
if (money > funds) {
throw new NotEnoughFundsException(0);
}
funds -= money;
}
public int refund(0) {
int refund = funds;
funds = 0;
return refund;
}
public int getAvailableFunds(0) {
return funds;
}
}
Brandon Johnson
900 PointsO okay cuhhhh!!!
4 Answers
Philip Gales
15,193 PointsVery confusing what they are asking, but here is my interpretation.
Now that we know that we should only have one behavior that we are asserting per test, can you help me break out the refundingReturnsAllAvailableFunds test case into a new one?
This tells me we are working with the refundingReturnsAllAvailableFunds() method in the CreditorTest class and that we are creating a new method so we can 'only have one behavior that we are asserting per test'.
How about making a new test that does the same, Arrange, Act and Assert named refundingResetsAvailableFundsToZero that separates out that final assertion in the first test.
Tells me to
- 'making a new test' -----> (create a new class)
- 'that does the same' -----> (use the same Arrange, Act and Assert)
- 'named refundingResetsAvailableFundsToZero' -----> (new method is named refundingResetsAvailableFundsToZero ())
The final code looks like this.
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());
}
@Test
public void refundingResetsAvailableFundsToZero() throws Exception { //<----new method
Creditor creditor = new Creditor();
creditor.addFunds(10);
int refund = creditor.refund();
assertEquals(10, refund);
assertEquals(0, creditor.getAvailableFunds());
}
}
Brandon Johnson
900 Pointsgood looking out Philip
Jeff Chiu
465 Pointsthanks for the explanation.
charles wachera
100 Pointsthanks man,,i was stuck too,, buh thanks to you,,, am a little beeter,,cheers man
ASHLEY H
4,408 PointsI appreciate the help Philip!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi there! Treehouse moderator here. I've edited the title of your question. Please refrain from using profanity in the Community. Thank you!