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 trialJason Anders
Treehouse Moderator 145,860 PointsGlitch in the testing for prepareSubmission?
I really do love these local challenges, except when something doesn't work. Everything is completed, the build and run produces exactly what it is supposed to, but when I try to run the Gradle prepareSubmission, all of a sudden there are three tests not passing? But the tests that aren't passing are producing the correct output, so the code has to be correct, right? Frustrated as ***, Yep!
edit: added failing tests, but shortened to post
com.teamtreehouse.challenges.homes.MainTest > menuIsInclusive FAILED
com.teamtreehouse.challenges.homes.MainTest > stateCodesIgnoreBlanks FAILED
com.teamtreehouse.challenges.homes.MainTest > stateCodesAreSorted FAILED
Jason Anders
Treehouse Moderator 145,860 Pointspublic static List<String> getStateCodesFromRecords(List<HousingRecord> records) {
return records.stream()
.map(HousingRecord::getState)
.filter(p -> p != null) // also tried .filter(Objects::nonNull)
.distinct()
.sorted()
.collect(Collectors.toList());
// TODO: Open a stream on records
// TODO: Map the stream to the state code
// TODO: Filter out any records without a state
// TODO: There are duplicate state codes in the records, make sure we have a unique representation
// TODO: Sort them alphabetically
// TODO: Collect them into a new list.
}
public static void displayStateCodeMenuDeclaratively(List<String> stateCodes) {
IntStream.range(1, stateCodes.size())
.mapToObj(i -> String.format("%d. %s", i, stateCodes.get(i)))
.forEach(System.out::println);
// TODO: Use a range to display a numbered list of the states, starting at 1.
}
Jason Anders
Treehouse Moderator 145,860 PointsWhen I build and run, the Imperative return has 1 -> 50, but #1 is empty. Mine (declarative) returns 1 -> 49 all sorted.
Craig Dennis
Treehouse TeacherTry using the zero index ( so i-1
)
Jason Anders
Treehouse Moderator 145,860 PointsIf I add 1 to the range and use a zero index, the run output is now the same as the imperative, and now the Submission is producing only 2 errors.
- com.teamtreehouse.challenges.homes.MainTest > stateCodesIgnoreBlanks FAILED
- com.teamtreehouse.challenges.homes.MainTest > stateCodesAreSorted FAILED
IntStream.range(1, stateCodes.size() + 1)
.mapToObj(i -> String.format("%d. %s", i, stateCodes.get(i-1)))
.forEach(System.out::println);
Craig Dennis
Treehouse TeacherRange closed no +1....sorry on phone
Jason Anders
Treehouse Moderator 145,860 PointsNo worries. Feel bad for bothering you, but I REALLY appreciate it. Thank-you very much.
Changed... Same 2 fails... here's more detailed stack
com.teamtreehouse.challenges.homes.MainTest > stateCodesIgnoreBlanks FAILED
java.lang.AssertionError: Make sure you to filter out the empty state codes in your 'getStateCodesFromRecords' method
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertFalse(Assert.java:64)
at com.teamtreehouse.challenges.homes.MainTest.stateCodesIgnoreBlanks(MainTest.java:139)
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)
Jason Anders
Treehouse Moderator 145,860 PointsIf you want to look at this during 'business hours' tomorrow, that'll be fine. I don't want to disturb your evening.
4 Answers
Craig Dennis
Treehouse TeacherAhhh i see ""
is not null but it is empty. ;)
Jason Anders
Treehouse Moderator 145,860 PointsThat's kind of funny... because I also just figured that out! After sifting through the debug. Haha.
Changed
.filter(p -> p != null) // also tried .filter(Objects::nonNull)
to
.filter(p -> p != "") // also tried .filter(Objects::nonNull)
and everything works. YAY!!!!!!
Thank you so much for taking the time to help me work through that. It is very much appreciated! You rock!
Jason Anders
Treehouse Moderator 145,860 PointsThat one really had me banging my head. Learned a great deal from working that though, so... good challenge! :)
William Daugherty
Full Stack JavaScript Techdegree Graduate 30,935 PointsYou used stateCodes.size() instead of regular integer for the range, you just ended hours of headache for me, thanks Jason lol
Ben Basty
23,772 Pointshi can anyone explain : .filter(p -> p != "")
Fernando Boza
25,384 PointsKinda late into the game but instead of filtering p with i just used
!state.isEmpty()
public static List<String> getStateCodesFromRecords(List<HousingRecord> records) {
return records.stream()
.map(HousingRecord::getState)
.filter(state -> !state.isEmpty())
.distinct()
.sorted()
.collect(Collectors.toList());
}
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherCan I see the method you wrote?