use of jakarta.nosql.mapping.Query in project jnosql-diana by eclipse.
the class DynamicQueryMethodReturnTest method shouldReturnFromPrepareStatement.
@Test
public void shouldReturnFromPrepareStatement() throws NoSuchMethodException {
PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
Mockito.when(preparedStatement.<Person>getResult()).thenReturn(Stream.of(new Person("Ada")));
Method method = getMethod(PersonRepository.class, "query");
Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withArgs(new Object[] { "Ada" }).withPrepareConverter(s -> preparedStatement).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Iterable);
Iterable<Person> persons = (List) execute;
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
}
Aggregations