COMMONSRDF-51: Ensure RDF4J stream closes in test
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/d5964a19 Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/d5964a19 Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/d5964a19 Branch: refs/heads/COMMONSRDF-47 Commit: d5964a19b274d60a0301680961dce087641623ce Parents: f5766fe Author: Stian Soiland-Reyes <[email protected]> Authored: Mon Jan 23 12:10:32 2017 +0000 Committer: Stian Soiland-Reyes <[email protected]> Committed: Mon Jan 23 12:10:32 2017 +0000 ---------------------------------------------------------------------- .../org/apache/commons/rdf/api/AbstractGraphTest.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d5964a19/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java index 4856ed4..8245b5d 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java @@ -495,6 +495,12 @@ public abstract class AbstractGraphTest { graph.remove(factory.createTriple(example1, greeting, upper)); } + private static Optional<? extends Triple> closableFindAny(Stream<? extends Triple> stream) { + try (Stream<? extends Triple> s = stream) { + return s.findAny(); + } + } + @Test public void streamLanguageTagsCaseInsensitive() { // COMMONSRDF-51: Ensure we can add/contains/remove with any casing @@ -510,12 +516,12 @@ public abstract class AbstractGraphTest { graph.add(example1, greeting, upper); // or as patterns - assertTrue(graph.stream(null, null, upper).findAny().isPresent()); - assertTrue(graph.stream(null, null, lower).findAny().isPresent()); - assertTrue(graph.stream(null, null, mixed).findAny().isPresent()); + assertTrue(closableFindAny(graph.stream(null, null, upper)).isPresent()); + assertTrue(closableFindAny(graph.stream(null, null, lower)).isPresent()); + assertTrue(closableFindAny(graph.stream(null, null, mixed)).isPresent()); // Check the triples returned equal a new triple - Triple t = graph.stream(null, null, lower).findAny().get(); + Triple t = closableFindAny(graph.stream(null, null, lower)).get(); assertEquals(t, factory.createTriple(example1, greeting, mixed)); }
