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 trial

Java Unit Testing in Java What to Test The Happy Path and Beyond

Optional Message Paramater causing error

When I added the optional message parameter "proper row" and "proper column", I was not able to get the test to finish. I received the error "java: cannot access java.util.function.Supplier class file for java.util.function.Supplier not found

3 Answers

Mateusz Majewski
Mateusz Majewski
8,721 Points

Try this, it works for me in JUnit 5 (message is on the last place, not first):

assertEquals(1, loc.getRow(), "proper row");

assertEquals(3, loc.getColumn(), "proper column");

Michael Loria
Michael Loria
5,651 Points

Not an expert but I was having the same issue, I think one of the main differences is that I was using JUnit 5 Jupiter and its imports and Craig uses JUnit 4. Using the right imports and annotations helped fix the issue for me.

I think it will work if you use these imports ( which I think comes from JUnit 4) :

   import org.junit.Before;
   import org.junit.Test;
   import static org.junit.Assert.assertEquals;

Here is my code (with the annotations I also used) :

class AlphaNumericChooserTest {

 private AlphaNumericChooser chooser;

 @Before
 void setUp() throws Exception {
     chooser = new AlphaNumericChooser(26, 10);
 }

 @org.junit.Test
 void validInputReturnsProperLocation() throws Exception {
     AlphaNumericChooser.Location loc = chooser.locationFromInput("B4");

     assertEquals( "proper row" , 1, loc.getRow());
     assertEquals( "proper column" , 3, loc.getColumn());
 }
}

Same. I was using JUnit 5 as well. But does that mean that optional message parameters are no longer used?

I'm a beginner and late for answering, but I hope this helps if someone gets here. I'm using JUnit 5 and optional message parameters seem to cause problems when running the tests, so I deleted them and found out that once you run the tests, the method which doesn't pass will be dotted underlined. So if I try with:

assertEquals(2, loc.getRow()); assertEquals(3, loc.getColumn());

the first method will be underlined.