#54 - Use Stream with try-with-resources.
Tweaked the integration test to use the Stream returned by the repository within a try-with-resources clause so that it gets closed correctly.
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package example.springdata.mongodb.people;
|
package example.springdata.mongodb.people;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -31,6 +33,7 @@ import example.springdata.mongodb.util.RequiresMongoDB;
|
|||||||
* Integration test for {@link PersonRepository}.
|
* Integration test for {@link PersonRepository}.
|
||||||
*
|
*
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
|
* @authot Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
|
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
|
||||||
@@ -67,6 +70,9 @@ public class PersonRepositoryIntegrationTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldPerformConversionDuringJava8StreamProcessing() {
|
public void shouldPerformConversionDuringJava8StreamProcessing() {
|
||||||
repository.findAllByCustomQueryWithStream().forEach(System.out::println);
|
|
||||||
|
try (Stream<Person> result = repository.findAllByCustomQueryWithStream()) {
|
||||||
|
result.forEach(System.out::println);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user