Test org.eclipse.rdf4j.query.QueryResults.asModel(result)

46 views Asked by At

What object can I pass to QueryResults.asModel() so when I test a method that runs the line:

final var model = QueryResults.asModel(result);

result has at least one Statement and asModel finishes correctly and returns what I set in the test?

when(queryResults.asModel(graphQueryResult)).thenReturn(model);

1

There are 1 answers

0
kidney On

Would this example help?

ValueFactory vf = SimpleValueFactory.getInstance();
Statement s = vf.createStatement(vf.createIRI("htp://example.org/type"), RDF.TYPE, OWL.CLASS);
CloseableIteration it = new IteratingGraphQueryResult(Collections.emptyMap(), List.of(s));
Model m = QueryResults.asModel(it);
assertEquals(new LinkedHashModel(List.of(s)), m);

Of course, it is possible to mock the result of QueryResults.asModel, but as it is a third-party code, it is generally advised to use it rather than mocking it.

Note that some of the types in the example are deprecated as of RDF4J 4.1.0, so they may not exist in the upcoming 5.0.0 release of RDF4J.