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

Shaun Wetzel
Shaun Wetzel
9,085 Points

Error during attempting to create submission

Using the housing dataset, let's produce a menu of all states represented in the data. Challenge in Using range to Produce a Menu.

running the code works but when going to create the submission it fails a test, here is the code

public static List<String> getStateCodesFromRecords(List<HousingRecord> records) {
    return records.stream()
      .map(HousingRecord::getState)
      .filter(String::isEmpty)
      .distinct()
      .sorted()
      .collect(Collectors.toList());
  }

public static void displayStateCodeMenuDeclaratively(List<String> stateCodes) {
    IntStream.rangeClosed(1, stateCodes.size())
      .mapToObj(i -> String.format("%d. %s %n", i, stateCodes.get(i - 1)))
      .forEach(System.out::println);
  }

here are the errors.

11:13:36 AM: Executing task 'prepareSubmission'...

:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava UP-TO-DATE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test

com.teamtreehouse.challenges.homes.MainTest > stateCodesAreSorted FAILED
    java.lang.AssertionError: Did you forget to sort the stream in the method 'getStateCodesFromRecords'
    Expected: iterable containing ["AZ", "WY"]
         but: item 0: was ""
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
        at org.junit.Assert.assertThat(Assert.java:865)
        at com.teamtreehouse.challenges.homes.MainTest.stateCodesAreSorted(MainTest.java:130)

10 tests completed, 1 failed
:test FAILED
4 actionable tasks: 2 executed, 2 up-to-date

FAILURE: Build failed with an exception.

as you can see in the getStateCodesFromRecords method stream i did .sorted() and even played around with some parameters in .sorted() with no luck.

1 Answer

Juan Jaramillo
Juan Jaramillo
5,482 Points

You're using .filter() and checking for Strings that are empy with the String::isEmpty method. A simple change to that and it should work. You should check for Strings that are NOT empty, you're doing the opposite.

Shaun Wetzel
Shaun Wetzel
9,085 Points

changed it to .filter(String -> !String.isEmpty())

and now the build works thank you!