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

Nik Omel
seal-mask
.a{fill-rule:evenodd;}techdegree
Nik Omel
Python Web Development Techdegree Student 7,496 Points

Bummer: There is a compiler error. Please click on preview to view your syntax errors!

Getting compile error, but I checked the code in IDE works as expected:

JavaTester.java:69: error: illegal start of expression package com.teamtreehouse.vending; ^ JavaTester.java:69: error: not a statement package com.teamtreehouse.vending; ^ JavaTester.java:71: error: illegal start of expression import org.junit.Test; ^ JavaTester.java:71: error: not a statement import org.junit.Test; ^ JavaTester.java:73: error: illegal start of expression import static org.junit.Assert.; ^ JavaTester.java:73: error: illegal start of expression import static org.junit.Assert.; ^ JavaTester.java:73: error: ';' expected import static org.junit.Assert.; ^ JavaTester.java:73: error: expected import static org.junit.Assert.; ^ JavaTester.java:73: error: illegal start of expression import static org.junit.Assert.*; ^ JavaTester.java:75: error: illegal start of expression public class CreditorTest { ^ 10 errors

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());
    }
}
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

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,547 Points

Hi Nik,

Currently, there seems to be some issues with the Java challenges and the Code Checker engines. I'm certain the Support Team is working hard and fast to fix the problem!

For the time being, I suggest continuing on with the course (if you'd like) by navigating over the challenge using the buttons in the progress bar above the video window.

Just make sure you come back later to complete the challenge so you receive full credit and the badge for the course. Hopefully everything gets up and going smoothly soon.

Keep Coding! :) :dizzy: