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

Marvin Deutz
Marvin Deutz
8,349 Points

Printer challenge tests broken?

So in the functional programming coding challenge I also get an error that 1 of the 3 tests failed.

16:02:09: Executing task 'prepareSubmission'...

:compileJava
:processResources NO-SOURCE
:classes
:compileTestJava UP-TO-DATE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
: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:58)

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:///Users/marv/Downloads/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 0s
3 actionable tasks: 2 executed, 1 up-to-date
There were failing tests. See the report at: file:///Users/marv/Downloads/lcc-java-fp-printer-1.1.0/build/reports/tests/test/index.html
16:02:10: Task execution finished 'prepareSubmission'.

But I think my code is correct. I just can't figure it out...

package com.teamtreehouse.challenges;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class Printer {

  public static void main(String[] args) {
    List<String> chipmunks = Arrays.asList("Alvin",
      "Simon",
      "Theodore");
    System.out.println("Imperative results:");
    printChipmunksImperatively(chipmunks);
    System.out.println("Declarative results:");
    printChipmunksDeclaratively(chipmunks);
  }

  public static void printChipmunksImperatively(List<String> chipmunks) {
    for (String chipmunk : chipmunks) {
      System.out.printf("%s! %n", chipmunk);
    }
  }

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


}

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

It seems to be missing that exclamation mark. Functionally it looks good ;)

Marvin Deutz
Marvin Deutz
8,349 Points

Thanks for the super quick response! Was almost banging my head against the wall because I couldn't figure it out.

Craig Dennis
Craig Dennis
Treehouse Teacher

No problem! Do you see it in the error message now?

Marvin Deutz
Marvin Deutz
8,349 Points

Yeah, thanks alot! Should've read everything instead of assuming that the test was broken. As soon as I looked at the imperative method I facepalmed. :D

Hie Craig l cant run Gradle can you please help

it would be nice if you can write better in PrinterTestclass to throw an exception " you are almost there, missing exclamation mark" .. lol.

Hello, I am also getting the error 1 out of three tests fail, and I have added the exclamation mark and it is still giving me errors?? Can anyone help? any help would be appreciated.

Task :compileJava FAILED C:\Users\Peter\Downloads\lcc-java-fp-printer-1.1.0\src\main\java\com\teamtreehouse\challenges\Printer.java:24: error: ')' expected chipmunks.forEach(chipmunk -> System.out.println(chipmunk!)); ^ 1 error

package com.teamtreehouse.challenges;

import java.util.Arrays; import java.util.List;

public class Printer {

public static void main(String[] args) { List<String> chipmunks = Arrays.asList("Alvin", "Simon", "Theodore"); System.out.println("Imperative results:"); printChipmunksImperatively(chipmunks); System.out.println("Declarative results:"); printChipmunksDeclaratively(chipmunks); }

public static void printChipmunksImperatively(List<String> chipmunks) { for (String chipmunk : chipmunks) { System.out.printf("%s! %n", chipmunk); } }

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

}

We have similar post here, please check: https://teamtreehouse.com/community/how-to-run-gradle-task