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 trialEdward Strudwick
2,036 PointsJUnit5: 'fail();' returns error: "java: cannot access java.util.function.Supplier..."
As above, running the test works fine and gives a green passed return. When I try to run fail() as in the video, I get the following error:
java: cannot access java.util.function.Supplier class file for java.util.function.Supplier not found
Google has been no help on this one I don't understand the error at all.
The same problem with the same tutorial was asked a year ago here: https://teamtreehouse.com/community/java-package-javautilfunction-does-not-exist
I'm assuming it's because the tutorial is Junit4 and there's some bit missing.
Getting more than a little fed up with issues on this Java course, that have no answers and no fix over a year on (have TTreehouse just left the Java course out to die a slow death?!?) . So any help much appreciated.
Edward Strudwick
2,036 PointsHi - it is different with JUnit5 - but yes I have these:
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*;
jb30
44,807 PointsI have the same imports as you, but my code is not giving me unexpected errors yet (it's failing the test like it's supposed to). One of my project's Test Dependencies is junit-jupitar-api-5.6.0.jar, so I think I'm on junit5.
What does your code look like? Inside my test class, I have
@Test
public void testThisTestMustFail() throws Exception {
fail("Failing test here.");
}
It also fails properly for me if I don't throw the Exception.
Edward Strudwick
2,036 PointsCheers jb30 for your help...see below.
2 Answers
Edward Strudwick
2,036 PointsSo I'll answer this myself as I have figured it out, in case it helps anyone else going forwards. Google told me: "Supplier<T> is an in-built functional interface introduced in Java 8 in the java.util.function package"
Despite only having the latest JDK, for some reason when I used the tutorial files from GitHub the Project SDK was set to a ridiculously early version and the language level was too. Under Project structure, once I changed the JDK to 16, and also set the language level to either 8 or 16, then fail() worked without the error. So it is a language level issue I believe to be aware of if you are using the current files from Github.
hamsternation
26,616 PointsTL;DR
In IntelliJ, go to:
File -> Project Structure -> Under Project Setting -> Project -> Set Language level to 8 or above.
voila!
Thanks Edward!
jb30
44,807 Pointsjb30
44,807 PointsDo you have
import static org.junit.Assert.*;
andimport org.junit.Test;
?