use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnSet.
@Test
public void shouldReturnSet() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getSet");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(streamPagination.apply(pagination)).thenReturn(Stream.of(new Person("Ada")));
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Set);
Set<Person> persons = (Set) execute;
Assertions.assertFalse(persons.isEmpty());
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination).apply(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnEmptyOptional.
@Test
public void shouldReturnEmptyOptional() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getOptional");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(singlePagination.apply(pagination)).thenReturn(Optional.empty());
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Optional);
Optional<Person> optional = (Optional) execute;
Assertions.assertFalse(optional.isPresent());
Mockito.verify(singlePagination).apply(pagination);
Mockito.verify(streamPagination, Mockito.never()).apply(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnCollection.
@Test
public void shouldReturnCollection() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getCollection");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(streamPagination.apply(pagination)).thenReturn(Stream.of(new Person("Ada")));
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Collection);
Collection<Person> persons = (Collection) execute;
Assertions.assertFalse(persons.isEmpty());
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination).apply(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnIterable.
@Test
public void shouldReturnIterable() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getIterable");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(streamPagination.apply(pagination)).thenReturn(Stream.of(new Person("Ada")));
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Iterable);
Iterable<Person> persons = (List) execute;
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination).apply(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnDeque.
@Test
public void shouldReturnDeque() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getDeque");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(streamPagination.apply(pagination)).thenReturn(Stream.of(new Person("Ada")));
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Deque);
Deque<Person> persons = (Deque) execute;
Assertions.assertFalse(persons.isEmpty());
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination).apply(pagination);
}
Aggregations