Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Unit Testing in Java How to Test Single Assertions Make For Better Tests

im getting two annoying errors that I cant figure how to correct

./com/teamtreehouse/vending/CreditorTest.java:39: error: reached end of file while parsing } ^ ./com/teamtreehouse/vending/CreditorTest.java:38: error: cannot find symbol assertEquals(0, creditor.GetAvailibleFunds());

com/teamtreehouse/vending/CreditorTest.java
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 refundingReturnsAllAvailibleFunds() throws Exception {
        Creditor creditor = new Creditor();
        creditor.addFunds(10);

        int refund = creditor.refund();

        assertEquals(10, refund);
        assertEquals(0, creditor.GetAvailibleFunds());
    }
com/teamtreehouse/vending/Creditor.java
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

cm21
cm21
150,853 Points

Hi Brandon,

  • That "reached end of file while parsing" error is because there is a need for one more '}' at the end of CreditorTest.java, so that the CreditorTest class is properly closed out and contained.

  • The second error is slightly more complicated on the surface, though the solution in this case is also quite simple, fortunately!

"./com/teamtreehouse/vending/CreditorTest.java:38: error: cannot find symbol assertEquals(0, creditor.GetAvailibleFunds()); ^ symbol: method GetAvailibleFunds() location: variable creditor of type Creditor 1 error"

Looking at those notes about symbol and location, what the Treehouse compiler is telling us is that it cannot find a method called 'GetAvailibleFunds' for creditor. The reason for this is a typo (the method's name is getAvailableFunds.)

Thus, the final three lines of CreditorTest.java will be:

        assertEquals(0, creditor.getAvailableFunds());
    }
}

Hope this helps!

I put in the lowercase but nothings changed