From 5f39f2a30a0721a7f41500ea22996419a301e2db Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 20 Aug 2019 18:38:09 -0500 Subject: [PATCH] updates the mapping-core --- .../query/AbstractColumnRepositoryProxy.java | 2 +- .../DefaultDynamicExecutorQueryConverter.java | 12 ++++---- .../artemis/reflection/DynamicReturn.java | 25 ++++++++--------- .../reflection/DynamicReturnConverter.java | 2 +- ...aultDynamicExecutorQueryConverterTest.java | 20 ++++++------- .../DynamicReturnPaginationTest.java | 28 +++++++++---------- .../artemis/reflection/DynamicReturnTest.java | 2 +- ...tionDynamicExecutorQueryConverterTest.java | 20 ++++++------- .../AbstractDocumentRepositoryProxy.java | 2 +- .../query/AbstractGraphRepositoryProxy.java | 2 +- 10 files changed, 56 insertions(+), 59 deletions(-) diff --git a/artemis/artemis-column/src/main/java/org/jnosql/artemis/column/query/AbstractColumnRepositoryProxy.java b/artemis/artemis-column/src/main/java/org/jnosql/artemis/column/query/AbstractColumnRepositoryProxy.java index f03ba490d..26075d629 100644 --- a/artemis/artemis-column/src/main/java/org/jnosql/artemis/column/query/AbstractColumnRepositoryProxy.java +++ b/artemis/artemis-column/src/main/java/org/jnosql/artemis/column/query/AbstractColumnRepositoryProxy.java @@ -87,7 +87,7 @@ private Object executeQuery(Method method, Object[] args, Class typeClass, Co DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(typeClass) .withMethodSource(method) - .withList(() -> getTemplate().select(query)) + .withResult(() -> getTemplate().select(query)) .withSingleResult(() -> getTemplate().singleResult(query)) .withPagination(DynamicReturn.findPagination(args)) .withListPagination(listPagination(query)) diff --git a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverter.java b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverter.java index 3f1566064..9d6ce2adc 100644 --- a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverter.java +++ b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverter.java @@ -45,32 +45,32 @@ public Optional toOptional(DynamicReturn dynamic) { @Override public List toList(DynamicReturn dynamic) { - return dynamic.list(); + return dynamic.result(); } @Override public Set toSet(DynamicReturn dynamic) { - return new HashSet<>(dynamic.list()); + return new HashSet<>(dynamic.result()); } @Override public LinkedList toLinkedList(DynamicReturn dynamic) { - return new LinkedList<>(dynamic.list()); + return new LinkedList<>(dynamic.result()); } @Override public Stream toStream(DynamicReturn dynamic) { - return dynamic.list().stream(); + return dynamic.result().stream(); } @Override public TreeSet toTreeSet(DynamicReturn dynamic) { - return new TreeSet<>(dynamic.list()); + return new TreeSet<>(dynamic.result()); } @Override public Object toDefault(DynamicReturn dynamic) { - return dynamic.list(); + return dynamic.result(); } @Override diff --git a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturn.java b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturn.java index b2d5ddcdd..50d9b70dc 100644 --- a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturn.java +++ b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturn.java @@ -43,7 +43,6 @@ */ public final class DynamicReturn implements MethodDynamicExecutable { - /** * A wrapper function that convert a result as a list to a result as optional * @@ -97,13 +96,11 @@ public static List findSorts(Object[] params) { return sorts; } - @Override public Object execute() { return DynamicReturnConverter.INSTANCE.convert(this); } - private static class SupplierConverter implements Function>, Supplier>> { private final Method method; @@ -136,7 +133,7 @@ public Supplier> apply(Supplier> l) { private final Supplier> singleResult; - private final Supplier> list; + private final Supplier> result; private final Pagination pagination; @@ -148,14 +145,14 @@ public Supplier> apply(Supplier> l) { private DynamicReturn(Class classSource, Method methodSource, Supplier> singleResult, - Supplier> list, Pagination pagination, + Supplier> result, Pagination pagination, Function> singleResultPagination, Function> listPagination, Function> page) { this.classSource = classSource; this.methodSource = methodSource; this.singleResult = singleResult; - this.list = list; + this.result = result; this.pagination = pagination; this.singleResultPagination = singleResultPagination; this.listPagination = listPagination; @@ -194,8 +191,8 @@ Optional singleResult() { * * @return the result as {@link List} */ - List list() { - return list.get(); + Stream result() { + return result.get(); } /** @@ -254,7 +251,7 @@ public static final class DefaultDynamicReturnBuilder { private Supplier> singleResult; - private Supplier> list; + private Supplier> result; private Pagination pagination; @@ -295,11 +292,11 @@ public DefaultDynamicReturnBuilder withSingleResult(Supplier> single } /** - * @param list the list + * @param result the list * @return the builder instance */ - public DefaultDynamicReturnBuilder withList(Supplier> list) { - this.list = list; + public DefaultDynamicReturnBuilder withResult(Supplier> result) { + this.result = result; return this; } @@ -349,7 +346,7 @@ public DynamicReturn build() { requireNonNull(classSource, "the class Source is required"); requireNonNull(methodSource, "the method Source is required"); requireNonNull(singleResult, "the single result supplier is required"); - requireNonNull(list, "the list result supplier is required"); + requireNonNull(result, "the result supplier is required"); if (pagination != null) { requireNonNull(singleResultPagination, "singleResultPagination is required when pagination is not null"); @@ -357,7 +354,7 @@ public DynamicReturn build() { requireNonNull(page, "page is required when pagination is not null"); } - return new DynamicReturn(classSource, methodSource, singleResult, list, + return new DynamicReturn(classSource, methodSource, singleResult, result, pagination, singleResultPagination, listPagination, page); } } diff --git a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturnConverter.java b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturnConverter.java index a0b319020..baa252925 100644 --- a/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturnConverter.java +++ b/artemis/artemis-core/src/main/java/org/jnosql/artemis/reflection/DynamicReturnConverter.java @@ -109,7 +109,7 @@ public Object convert(DynamicQueryMethodReturn dynamicQueryMethod) { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(typeClass) .withMethodSource(method) - .withList(streamSupplier) + .withResult(streamSupplier) .withSingleResult(singleSupplier) .build(); diff --git a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverterTest.java b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverterTest.java index c07c3b816..3eefb529b 100644 --- a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverterTest.java +++ b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DefaultDynamicExecutorQueryConverterTest.java @@ -48,7 +48,7 @@ public void shouldReturnInstance() { dynamic = DynamicReturn.builder() .withSingleResult(() -> Optional.of(ada)) .withClassSource(Person.class) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Person person = converter.toInstance(dynamic); @@ -61,7 +61,7 @@ public void shouldReturnNullAsInstance() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Person person = converter.toInstance(dynamic); @@ -75,7 +75,7 @@ public void shouldReturnOptional() { dynamic = DynamicReturn.builder() .withSingleResult(() -> Optional.of(ada)) .withClassSource(Person.class) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Optional person = converter.toOptional(dynamic); @@ -90,7 +90,7 @@ public void shouldReturnList() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); List person = converter.toList(dynamic); @@ -105,7 +105,7 @@ public void shouldReturnSet() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Set person = converter.toSet(dynamic); @@ -121,7 +121,7 @@ public void shouldReturnLinkedList() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); LinkedList person = converter.toLinkedList(dynamic); @@ -136,7 +136,7 @@ public void shouldReturnTreeSet() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); TreeSet person = converter.toTreeSet(dynamic); @@ -151,7 +151,7 @@ public void shouldReturnStream() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Stream person = converter.toStream(dynamic); @@ -166,7 +166,7 @@ public void shouldReturnDefault() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Object person = converter.toDefault(dynamic); @@ -180,7 +180,7 @@ public void shouldReturnErrorWhenUsePage() { dynamic = DynamicReturn.builder() .withSingleResult(Optional::empty) .withClassSource(Person.class) - .withList(() -> Collections.singletonList(ada)) + .withResult(() -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) .build(); Assertions.assertThrows(DynamicQueryException.class, () -> converter.toPage(dynamic)); diff --git a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnPaginationTest.java b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnPaginationTest.java index c33a384ac..dcfbb8c9e 100644 --- a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnPaginationTest.java +++ b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnPaginationTest.java @@ -67,7 +67,7 @@ public void shouldReturnEmptyOptional() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -96,7 +96,7 @@ public void shouldReturnOptional() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -124,7 +124,7 @@ public void shouldReturnAnInstance() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -151,7 +151,7 @@ public void shouldReturnNull() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -178,7 +178,7 @@ public void shouldReturnList() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -206,7 +206,7 @@ public void shouldReturnIterable() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -234,7 +234,7 @@ public void shouldReturnCollection() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -261,7 +261,7 @@ public void shouldReturnSet() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -288,7 +288,7 @@ public void shouldReturnQueue() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -316,7 +316,7 @@ public void shouldReturnStream() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -342,7 +342,7 @@ public void shouldReturnSortedSet() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -369,7 +369,7 @@ public void shouldReturnNavigableSet() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -397,7 +397,7 @@ public void shouldReturnDeque() throws NoSuchMethodException { DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) @@ -421,7 +421,7 @@ public void shouldReturnErrorWhenExecutePage() throws NoSuchMethodException { Pagination pagination = getPagination(); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) - .withMethodSource(method).withList(stream) + .withMethodSource(method).withResult(stream) .withSingleResult(singleResult) .withPagination(pagination) .withListPagination(listPagination) diff --git a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnTest.java b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnTest.java index 9d9104f59..5a6504953 100644 --- a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnTest.java +++ b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/DynamicReturnTest.java @@ -1 +1 @@ -/* * Copyright (c) 2019 Otávio Santana and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Apache License v2.0 which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. * * You may elect to redistribute this code under either of these licenses. * * Contributors: * * Otavio Santana */ package org.jnosql.artemis.reflection; import jakarta.nosql.NonUniqueResultException; import jakarta.nosql.Sort; import jakarta.nosql.mapping.DynamicQueryException; import jakarta.nosql.mapping.Page; import jakarta.nosql.mapping.Pagination; import jakarta.nosql.mapping.Repository; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Deque; import java.util.List; import java.util.NavigableSet; import java.util.Objects; import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.SortedSet; import java.util.function.Supplier; import java.util.stream.Stream; import static jakarta.nosql.mapping.Sorts.sorts; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.jnosql.artemis.reflection.DynamicReturn.findSorts; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; class DynamicReturnTest { @Test public void shouldReturnNPEWhenThereIsPagination() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); assertThrows(NullPointerException.class, () -> DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult) .withPagination(Pagination.page(1L).size(2L)).build()); } @Test public void shouldReturnEmptyOptional() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Optional); Optional optional = (Optional) execute; Assertions.assertFalse(optional.isPresent()); } @Test public void shouldReturnOptional() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Optional); Optional optional = (Optional) execute; assertTrue(optional.isPresent()); Assertions.assertEquals(new Person("Ada"), optional.get()); } @Test public void shouldReturnOptionalError() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = () -> Stream.of(new Person("Poliana"), new Person("Otavio")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); assertThrows(NonUniqueResultException.class, dynamicReturn::execute); } @Test public void shouldReturnAnInstance() { Method method = getMethod(PersonRepository.class, "getInstance"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Person); Person person = (Person) execute; Assertions.assertEquals(new Person("Ada"), person); } @Test public void shouldReturnNull() { Method method = getMethod(PersonRepository.class, "getInstance"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertNull(execute); } @Test public void shouldReturnList() { Method method = getMethod(PersonRepository.class, "getList"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof List); List persons = (List) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.get(0)); } @Test public void shouldReturnIterable() { Method method = getMethod(PersonRepository.class, "getIterable"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Iterable); Iterable persons = (List) execute; Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnCollection() { Method method = getMethod(PersonRepository.class, "getCollection"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Collection); Collection persons = (Collection) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnSet() { Method method = getMethod(PersonRepository.class, "getSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Set); Set persons = (Set) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnQueue() { Method method = getMethod(PersonRepository.class, "getQueue"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Queue); Queue persons = (Queue) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnStream() { Method method = getMethod(PersonRepository.class, "getStream"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Stream); Stream persons = (Stream) execute; Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnSortedSet() { Method method = getMethod(PersonRepository.class, "getSortedSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof SortedSet); SortedSet persons = (SortedSet) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnNavigableSet() { Method method = getMethod(PersonRepository.class, "getNavigableSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof NavigableSet); NavigableSet persons = (NavigableSet) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnDeque() { Method method = getMethod(PersonRepository.class, "getDeque"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Deque); Deque persons = (Deque) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnErrorWhenExecutePage() { Method method = getMethod(PersonRepository.class, "getPage"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); assertThrows(DynamicQueryException.class, dynamicReturn::execute); } @Test public void shouldReturnErrorNavigableSetEntityIsNotComparable() { Method method = getMethod(AnimalRepository.class, "getSortedSet"); Supplier> stream = () -> Stream.of(new Animal("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Animal.class) .withMethodSource(method).withList(stream) .withSingleResult(singlResult).build(); assertThrows(DynamicQueryException.class, dynamicReturn::execute); } @Test public void shouldReturnNullWhenParamIsEmptyOnFindPagination() { assertNull(DynamicReturn.findPagination(null)); assertNull(DynamicReturn.findPagination(new Object[0])); } @Test public void shouldFindPagination() { Pagination pagination = Pagination.page(1L).size(2); Pagination pagination1 = DynamicReturn.findPagination(new Object[]{"value", 23, pagination}); Assertions.assertEquals(pagination, pagination1); } @Test public void shouldReturnNullWhenThereIsNotPagination() { Pagination pagination = DynamicReturn.findPagination(new Object[]{"value", 23, BigDecimal.TEN}); assertNull(pagination); } @Test public void shouldReturnEmptyWhenThereIsNotParametersAtSorts() { assertTrue(findSorts(null).isEmpty()); assertTrue(findSorts(new Object[0]).isEmpty()); } @Test public void shouldShouldFindSortAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), name, age}); assertThat(sorts, Matchers.contains(name, age)); } @Test public void shouldShouldFindSortsAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), sorts().add(name).add(age)}); assertThat(sorts, Matchers.contains(name, age)); } @Test public void shouldShouldFindSortAndSortsAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), name, age, sorts().desc("name").asc("age")}); assertThat(sorts, Matchers.contains(name, age, Sort.desc("name"), Sort.asc("age"))); } @Test public void shouldFindEmptyListWhenThereIsNotSortOrSorts() { List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2)}); assertTrue(sorts.isEmpty()); } private Method getMethod(Class repository, String methodName) { return Stream.of(repository.getDeclaredMethods()) .filter(m -> m.getName().equals(methodName)) .findFirst().get(); } private static class Animal { private final String name; private Animal(String name) { this.name = name; } } private static class Person implements Comparable { private final String name; private Person(String name) { this.name = name; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Person person = (Person) o; return Objects.equals(name, person.name); } @Override public int hashCode() { return Objects.hashCode(name); } @Override public int compareTo(Person o) { return name.compareTo(o.name); } } private interface AnimalRepository extends Repository { SortedSet getSortedSet(); } private interface PersonRepository extends Repository { Optional getOptional(); Person getInstance(); List getList(); Iterable getIterable(); Collection getCollection(); Set getSet(); Queue getQueue(); Stream getStream(); SortedSet getSortedSet(); NavigableSet getNavigableSet(); Deque getDeque(); Page getPage(); } } \ No newline at end of file +/* * Copyright (c) 2019 Otávio Santana and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Apache License v2.0 which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. * * You may elect to redistribute this code under either of these licenses. * * Contributors: * * Otavio Santana */ package org.jnosql.artemis.reflection; import jakarta.nosql.NonUniqueResultException; import jakarta.nosql.Sort; import jakarta.nosql.mapping.DynamicQueryException; import jakarta.nosql.mapping.Page; import jakarta.nosql.mapping.Pagination; import jakarta.nosql.mapping.Repository; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.Collection; import java.util.Deque; import java.util.List; import java.util.NavigableSet; import java.util.Objects; import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.SortedSet; import java.util.function.Supplier; import java.util.stream.Stream; import static jakarta.nosql.mapping.Sorts.sorts; import static org.hamcrest.MatcherAssert.assertThat; import static org.jnosql.artemis.reflection.DynamicReturn.findSorts; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; class DynamicReturnTest { @Test public void shouldReturnNPEWhenThereIsPagination() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); assertThrows(NullPointerException.class, () -> DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult) .withPagination(Pagination.page(1L).size(2L)).build()); } @Test public void shouldReturnEmptyOptional() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Optional); Optional optional = (Optional) execute; Assertions.assertFalse(optional.isPresent()); } @Test public void shouldReturnOptional() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Optional); Optional optional = (Optional) execute; assertTrue(optional.isPresent()); Assertions.assertEquals(new Person("Ada"), optional.get()); } @Test public void shouldReturnOptionalError() { Method method = getMethod(PersonRepository.class, "getOptional"); Supplier> stream = () -> Stream.of(new Person("Poliana"), new Person("Otavio")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); assertThrows(NonUniqueResultException.class, dynamicReturn::execute); } @Test public void shouldReturnAnInstance() { Method method = getMethod(PersonRepository.class, "getInstance"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Person); Person person = (Person) execute; Assertions.assertEquals(new Person("Ada"), person); } @Test public void shouldReturnNull() { Method method = getMethod(PersonRepository.class, "getInstance"); Supplier> stream = Stream::empty; Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertNull(execute); } @Test public void shouldReturnList() { Method method = getMethod(PersonRepository.class, "getList"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof List); List persons = (List) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.get(0)); } @Test public void shouldReturnIterable() { Method method = getMethod(PersonRepository.class, "getIterable"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Iterable); Iterable persons = (List) execute; Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnCollection() { Method method = getMethod(PersonRepository.class, "getCollection"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Collection); Collection persons = (Collection) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnSet() { Method method = getMethod(PersonRepository.class, "getSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Set); Set persons = (Set) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnQueue() { Method method = getMethod(PersonRepository.class, "getQueue"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Queue); Queue persons = (Queue) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnStream() { Method method = getMethod(PersonRepository.class, "getStream"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Stream); Stream persons = (Stream) execute; Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnSortedSet() { Method method = getMethod(PersonRepository.class, "getSortedSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof SortedSet); SortedSet persons = (SortedSet) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnNavigableSet() { Method method = getMethod(PersonRepository.class, "getNavigableSet"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof NavigableSet); NavigableSet persons = (NavigableSet) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnDeque() { Method method = getMethod(PersonRepository.class, "getDeque"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); Object execute = dynamicReturn.execute(); assertTrue(execute instanceof Deque); Deque persons = (Deque) execute; Assertions.assertFalse(persons.isEmpty()); Assertions.assertEquals(new Person("Ada"), persons.iterator().next()); } @Test public void shouldReturnErrorWhenExecutePage() { Method method = getMethod(PersonRepository.class, "getPage"); Supplier> stream = () -> Stream.of(new Person("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Person.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); assertThrows(DynamicQueryException.class, dynamicReturn::execute); } @Test public void shouldReturnErrorNavigableSetEntityIsNotComparable() { Method method = getMethod(AnimalRepository.class, "getSortedSet"); Supplier> stream = () -> Stream.of(new Animal("Ada")); Supplier> singlResult = DynamicReturn.toSingleResult(method).apply(stream); DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(Animal.class) .withMethodSource(method).withResult(stream) .withSingleResult(singlResult).build(); assertThrows(DynamicQueryException.class, dynamicReturn::execute); } @Test public void shouldReturnNullWhenParamIsEmptyOnFindPagination() { assertNull(DynamicReturn.findPagination(null)); assertNull(DynamicReturn.findPagination(new Object[0])); } @Test public void shouldFindPagination() { Pagination pagination = Pagination.page(1L).size(2); Pagination pagination1 = DynamicReturn.findPagination(new Object[]{"value", 23, pagination}); Assertions.assertEquals(pagination, pagination1); } @Test public void shouldReturnNullWhenThereIsNotPagination() { Pagination pagination = DynamicReturn.findPagination(new Object[]{"value", 23, BigDecimal.TEN}); assertNull(pagination); } @Test public void shouldReturnEmptyWhenThereIsNotParametersAtSorts() { assertTrue(findSorts(null).isEmpty()); assertTrue(findSorts(new Object[0]).isEmpty()); } @Test public void shouldShouldFindSortAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), name, age}); assertThat(sorts, Matchers.contains(name, age)); } @Test public void shouldShouldFindSortsAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), sorts().add(name).add(age)}); assertThat(sorts, Matchers.contains(name, age)); } @Test public void shouldShouldFindSortAndSortsAtMethod() { Sort name = Sort.asc("name"); Sort age = Sort.desc("age"); List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2), name, age, sorts().desc("name").asc("age")}); assertThat(sorts, Matchers.contains(name, age, Sort.desc("name"), Sort.asc("age"))); } @Test public void shouldFindEmptyListWhenThereIsNotSortOrSorts() { List sorts = findSorts(new Object[]{"Otavio", 23, Pagination.page(2).size(2)}); assertTrue(sorts.isEmpty()); } private Method getMethod(Class repository, String methodName) { return Stream.of(repository.getDeclaredMethods()) .filter(m -> m.getName().equals(methodName)) .findFirst().get(); } private static class Animal { private final String name; private Animal(String name) { this.name = name; } } private static class Person implements Comparable { private final String name; private Person(String name) { this.name = name; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Person person = (Person) o; return Objects.equals(name, person.name); } @Override public int hashCode() { return Objects.hashCode(name); } @Override public int compareTo(Person o) { return name.compareTo(o.name); } } private interface AnimalRepository extends Repository { SortedSet getSortedSet(); } private interface PersonRepository extends Repository { Optional getOptional(); Person getInstance(); List getList(); Iterable getIterable(); Collection getCollection(); Set getSet(); Queue getQueue(); Stream getStream(); SortedSet getSortedSet(); NavigableSet getNavigableSet(); Deque getDeque(); Page getPage(); } } \ No newline at end of file diff --git a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/PaginationDynamicExecutorQueryConverterTest.java b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/PaginationDynamicExecutorQueryConverterTest.java index eacaba987..dadfcf510 100644 --- a/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/PaginationDynamicExecutorQueryConverterTest.java +++ b/artemis/artemis-core/src/test/java/org/jnosql/artemis/reflection/PaginationDynamicExecutorQueryConverterTest.java @@ -61,7 +61,7 @@ public void shouldReturnInstance() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.of(ada)) .withListPagination(p -> Collections.emptyList()) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -78,7 +78,7 @@ public void shouldReturnNullAsInstance() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.emptyList()) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -96,7 +96,7 @@ public void shouldReturnOptional() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.of(ada)) .withListPagination(p -> Collections.emptyList()) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -115,7 +115,7 @@ public void shouldReturnList() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -134,7 +134,7 @@ public void shouldReturnSet() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -154,7 +154,7 @@ public void shouldReturnLinkedList() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -173,7 +173,7 @@ public void shouldReturnTreeSet() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -192,7 +192,7 @@ public void shouldReturnStream() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -211,7 +211,7 @@ public void shouldReturnDefault() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) @@ -232,7 +232,7 @@ public void shouldReturnErrorWhenUsePage() { dynamic = DynamicReturn.builder() .withClassSource(Person.class) .withSingleResult(Optional::empty) - .withList(Collections::emptyList) + .withResult(Collections::emptyList) .withSingleResultPagination(p -> Optional.empty()) .withListPagination(p -> Collections.singletonList(ada)) .withMethodSource(Person.class.getDeclaredMethods()[0]) diff --git a/artemis/artemis-document/src/main/java/org/jnosql/artemis/document/query/AbstractDocumentRepositoryProxy.java b/artemis/artemis-document/src/main/java/org/jnosql/artemis/document/query/AbstractDocumentRepositoryProxy.java index ec5da6d76..6b25a8ebc 100644 --- a/artemis/artemis-document/src/main/java/org/jnosql/artemis/document/query/AbstractDocumentRepositoryProxy.java +++ b/artemis/artemis-document/src/main/java/org/jnosql/artemis/document/query/AbstractDocumentRepositoryProxy.java @@ -86,7 +86,7 @@ private Object executeQuery(Method method, Object[] args, Class typeClass, Do DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(typeClass) .withMethodSource(method) - .withList(() -> getTemplate().select(query)) + .withResult(() -> getTemplate().select(query)) .withSingleResult(() -> getTemplate().singleResult(query)) .withPagination(DynamicReturn.findPagination(args)) .withListPagination(listPagination(query)) diff --git a/artemis/artemis-graph/src/main/java/org/jnosql/artemis/graph/query/AbstractGraphRepositoryProxy.java b/artemis/artemis-graph/src/main/java/org/jnosql/artemis/graph/query/AbstractGraphRepositoryProxy.java index ff814693c..155b938de 100644 --- a/artemis/artemis-graph/src/main/java/org/jnosql/artemis/graph/query/AbstractGraphRepositoryProxy.java +++ b/artemis/artemis-graph/src/main/java/org/jnosql/artemis/graph/query/AbstractGraphRepositoryProxy.java @@ -147,7 +147,7 @@ private Object converter(Method method, Class typeClass, DynamicReturn dynamicReturn = DynamicReturn.builder() .withClassSource(typeClass) .withMethodSource(method) - .withList(querySupplier) + .withResult(querySupplier) .withSingleResult(singleSupplier) .withPagination(DynamicReturn.findPagination(args)) .withListPagination(p -> querySupplier.get())