• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display All Books Published On Specific Day  RSS feed

 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working a big assignment with a JUnit test and I'm trying to solve a method that iterates through books and display the ones published on a specified day. But my output isn't matching what is required. Below I'm going to post my method, Eclipse's Junit Failure Trace, and the TestAssignment assert:



Failure Trace:

org.junit.ComparisonFailure: -1 point. expected:<[]No books were publis...> but was:<[6
3
2
0
4
3
4
2
4
4
]No books were publis...>

@Test:



Any tips to avoid iterating when there are no books published on a Sunday for example? I tried a it.Remove() with an if statement and wouldn't fix it. Any help would be awesome! Thanks.

 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to tell what's going wrong because you've only posted snippets of code, but I'll give it a try.

In line 9 of the first code block, what is the return value of getDayOfTheWeek()?

If that doesn't help solve the problem, please post the complete classes of Book and the JUnit test.
 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few hours later I solved it:

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing hasDay = false; in line 19? If you're in that if-block, hasDay is already false. Setting it to false again effectively does nothing.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be a more elegant way to do that with a Stream. Please post your Book class and also how you are creating the List, then let's see if we can't get a Stream to do all the hard work for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!