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 trialSimbarashe Pande
13,507 Pointsi am having errors with my tests please help
1:44:56 PM: Executing task 'prepareSubmission'...
:compileJava UP-TO-DATE :processResources NO-SOURCE :classes UP-TO-DATE :compileTestJava :processTestResources NO-SOURCE :testClasses :test
com.teamtreehouse.challenges.PrinterTest > printsProperly FAILED java.lang.AssertionError: The output from your method 'printChipmunksDeclaratively' seems wrong Expected: a string containing "Example1!" but: was "Example1 Example2 Example3 " at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.junit.Assert.assertThat(Assert.java:865) at com.teamtreehouse.teachingassistant.rules.Consoler.assertExpected(Consoler.java:61) at com.teamtreehouse.challenges.PrinterTest.printsProperly(PrinterTest.java:59)
3 tests completed, 1 failed :test FAILED
FAILURE: Build failed with an exception.
-
What went wrong: Execution failed for task ':test'.
There were failing tests. See the report at: file:///C:/Users/simbarashe%20pande/Desktop/lcc-java-fp-printer-1.1.0/build/reports/tests/test/index.html
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 2s 3 actionable tasks: 2 executed, 1 up-to-date There were failing tests. See the report at: file:///C:/Users/simbarashe%20pande/Desktop/lcc-java-fp-printer-1.1.0/build/reports/tests/test/index.html 1:44:58 PM: Task execution finished 'prepareSubmission'.
And here is my printerTest.java package com.teamtreehouse.challenges;
import com.teamtreehouse.ast.Inspector; import com.teamtreehouse.ast.predicates.Expressions; import com.teamtreehouse.ast.predicates.Methods; import com.teamtreehouse.ast.rules.Sourcery; import com.teamtreehouse.teachingassistant.rules.Consoler;
import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertTrue;
public class PrinterTest { public static final String METHOD_NAME = "printChipmunksDeclaratively"; private Inspector inspector;
@ClassRule public static Sourcery sourcery = new Sourcery();
@Rule public Consoler consoler = new Consoler();
@Before public void setUp() throws Exception { inspector = sourcery.inspectorFor(Printer.class); }
@Test public void declarativeMethodExists() throws Exception { String msg = String.format("Whoops! Looks like you accidentally removed the '%s' method", METHOD_NAME); assertTrue(msg, inspector.hasMethodNamed(METHOD_NAME)); }
@Test public void declarativelyUsesForEach() throws Exception { String msg = String.format("Ensure you use forEach in the more declarative '%s' method", METHOD_NAME); assertTrue(msg, inspector.matchingChain(chain -> chain .withMethod(Methods.named(METHOD_NAME)) .withExpression(Expressions.isMethodCall().and( Expressions.containing("forEach"))))); }
@Test public void printsProperly() throws Exception { Printer.printChipmunksDeclaratively(Arrays.asList("Example1", "Example2")); Printer.printChipmunksDeclaratively(Arrays.asList("Example3")); consoler.addExpectedPrompt("Example1!"); consoler.addExpectedPrompt("Example2!"); consoler.addExpectedPrompt("Example3!"); String msg = String.format("The output from your method '%s' seems wrong", METHOD_NAME); consoler.assertExpected(msg); } }
3 Answers
Mohamad Kenas
17,896 PointsYou need to print out the exclamation mark as Steven said. You can do it like this :
chipmunks.forEach(chipmunk -> System.out.println(chipmunk + "!"));
Steven Thomas
2,911 PointsThe issue is that you are not printing the !. Your print statements need to match the way they produce printChipmunksImperatively method. Ex: Simon!
Your code will print simply Simon which is why the test is failing.
Simbarashe Pande
13,507 Pointsthanx for the reply Steven, please explain using code example i am still not getting it
Marvin Deutz
8,349 PointsI have the same problem. I am quite sure that my code is correct.
public static void printChipmunksDeclaratively(List<String> chipmunks) {
// TODO: Print out each of the chipmunks using the forEach method on Iterable
chipmunks.forEach(chipmunk -> System.out.println(chipmunk));
}