You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/17 19:28:53 UTC
[isis] branch master updated: ISIS-2033: fixes query related tests
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 8db0625 ISIS-2033: fixes query related tests
8db0625 is described below
commit 8db062505191656615868b567fc2476fc608d725
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Dec 17 20:28:37 2020 +0100
ISIS-2033: fixes query related tests
---
.../src/main/java/org/apache/isis/applib/query/Query.java | 7 +++++--
.../apache/isis/applib/query/_AllInstancesQueryDefault.java | 4 ++--
.../org/apache/isis/applib/query/_NamedQueryDefault.java | 4 ++--
.../applib/query/NamedQueryTest_withStart_or_withCount.java | 12 +++++-------
.../runtimeservices/repository/RepositoryServiceDefault.java | 4 ++--
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/query/Query.java b/api/applib/src/main/java/org/apache/isis/applib/query/Query.java
index b10d790..b02f794 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/query/Query.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/query/Query.java
@@ -50,6 +50,9 @@ import lombok.NonNull;
* @since 1.x revised for 2.0 {@index}
*/
public interface Query<T> extends Serializable {
+
+ public static long UNLIMITED_COUNT = 0L;
+
/**
* The {@link Class} of the objects returned by this query.
@@ -84,13 +87,13 @@ public interface Query<T> extends Serializable {
public static <T> Query<T> allInstances(
final @NonNull Class<T> resultType) {
- return new _AllInstancesQueryDefault<>(resultType, 0, Long.MAX_VALUE);
+ return new _AllInstancesQueryDefault<>(resultType, 0, UNLIMITED_COUNT);
}
public static <T> NamedQuery<T> named(
final @NonNull Class<T> resultType,
final @NonNull String queryName) {
- return new _NamedQueryDefault<>(resultType, queryName, 0, Long.MAX_VALUE, null);
+ return new _NamedQueryDefault<>(resultType, queryName, 0, UNLIMITED_COUNT, null);
}
}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/query/_AllInstancesQueryDefault.java b/api/applib/src/main/java/org/apache/isis/applib/query/_AllInstancesQueryDefault.java
index 6a15e53..0c74068 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/query/_AllInstancesQueryDefault.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/query/_AllInstancesQueryDefault.java
@@ -58,8 +58,8 @@ implements AllInstancesQuery<T> {
@Override
public _AllInstancesQueryDefault<T> withCount(final long count) {
- if(count<=0) {
- throw _Exceptions.illegalArgument("require count>0, got %d", count);
+ if(count<0) {
+ throw _Exceptions.illegalArgument("require count>=0, got %d", count);
}
return new _AllInstancesQueryDefault<>(getResultType(), getStart(), count);
}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/query/_NamedQueryDefault.java b/api/applib/src/main/java/org/apache/isis/applib/query/_NamedQueryDefault.java
index 31775ef..c90a3ce 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/query/_NamedQueryDefault.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/query/_NamedQueryDefault.java
@@ -72,8 +72,8 @@ implements NamedQuery<T> {
@Override
public _NamedQueryDefault<T> withCount(final long count) {
- if(count<=0) {
- throw _Exceptions.illegalArgument("require count>0, got %d", count);
+ if(count<0) {
+ throw _Exceptions.illegalArgument("require count>=0, got %d", count);
}
return new _NamedQueryDefault<>(getResultType(), getName(), getStart(), count, getParametersByName());
}
diff --git a/api/applib/src/test/java/org/apache/isis/applib/query/NamedQueryTest_withStart_or_withCount.java b/api/applib/src/test/java/org/apache/isis/applib/query/NamedQueryTest_withStart_or_withCount.java
index 884fba6..c8cb655 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/query/NamedQueryTest_withStart_or_withCount.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/query/NamedQueryTest_withStart_or_withCount.java
@@ -41,7 +41,7 @@ class NamedQueryTest_withStart_or_withCount {
@Test
public void defaults() throws Exception {
assertThat(namedQuery.getStart(), is(0L));
- assertThat(namedQuery.getCount(), is(0L));
+ assertThat(namedQuery.getCount(), is(Query.UNLIMITED_COUNT));
}
@Test
@@ -59,7 +59,7 @@ class NamedQueryTest_withStart_or_withCount {
final NamedQuery<Customer> q = namedQuery.withStart(10L);
assertThat(q.getStart(), is(10L));
- assertThat(q.getCount(), is(0L));
+ assertThat(q.getCount(), is(Query.UNLIMITED_COUNT));
}
@Test
@@ -80,7 +80,6 @@ class NamedQueryTest_withStart_or_withCount {
public void happyCase_countOnly() throws Exception {
final NamedQuery<Customer> q = namedQuery.withCount(20L);
- assertThat(q, is(namedQuery));
assertThat(q.getStart(), is(0L));
assertThat(q.getCount(), is(20L));
}
@@ -93,10 +92,9 @@ class NamedQueryTest_withStart_or_withCount {
}
@Test
- public void countZero() throws Exception {
- assertThrows(IllegalArgumentException.class, ()->{
- namedQuery.withCount(0);
- });
+ public void countUnlimited() throws Exception {
+ final NamedQuery<Customer> q = namedQuery.withCount(Query.UNLIMITED_COUNT);
+ assertThat(q.getCount(), is(Query.UNLIMITED_COUNT));
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
index 359bc1e..af32f9c 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
@@ -197,14 +197,14 @@ public class RepositoryServiceDefault implements RepositoryService {
@Override
public <T> Optional<T> firstMatch(final Class<T> type, final Predicate<T> predicate) {
- final List<T> instances = allMatches(type, predicate, 0, 2); // No need to fetch more than 2.
+ final List<T> instances = allMatches(type, predicate);
return firstInstanceElseEmpty(instances);
}
@Override
public <T> Optional<T> firstMatch(final Query<T> query) {
- final List<T> instances = allMatches(query); // No need to fetch more than 2.
+ final List<T> instances = allMatches(query);
return firstInstanceElseEmpty(instances);
}