title: JUnit assertions within in Java 8 stream
body: <p>Say I have three objects that I save to the database and set the db generated ID into. I don't know the order of the objects returned from the method <code>saveToDb</code>. But I want to junit test that those generated IDs are there. How do I do that within in stream? I want to do something like this:</p>
  
  <pre><code>List&lt;MyObject&gt; myObjects = getObjects();
  numRecords = saveToDb(myObjects); // numRecords=3
  List&lt;Integer&gt; intArray = Arrays.asList(1, 2, 3);
  intArray.stream()
    .forEach(it -&gt; myObjects.stream()
      .filter(it2 -&gt; it2.getId().equals(it))
      .????
  </code></pre>
  
  <p>But I'm not sure where my <code>assertEquals()</code> would go in a statement like this. Or is my approach all wrong? I know I could use a simple for-loop, but I like the elegance of streams. Additionally, is there a way to dynamically create the intArray, in case I have more than 3 myObjects?</p>