Repository: jakartaee/data
Pull request #34 (2022-10-04 18:41:24)

Add test on Limit class


Patch:
diff --git a/api/src/main/java/jakarta/data/repository/Limit.java b/api/src/main/java/jakarta/data/repository/Limit.java
index 9fa8884e..c8748d50 100644
--- a/api/src/main/java/jakarta/data/repository/Limit.java
+++ b/api/src/main/java/jakarta/data/repository/Limit.java
@@ -44,6 +44,7 @@ package jakarta.data.repository;
  * </ul>
  */
 public class Limit {
+    private static final long DEFAULT_START_AT = 1L;
     private final long maxResults;
     private final long startAt;
 
@@ -84,8 +85,8 @@ public class Limit {
      *         or <code>&#64;Query</code> method.
      * @throws IllegalArgumentException if maxResults is less than 1.
      */
-    public Limit of(long maxResults) {
-        return new Limit(maxResults, 1L);
+    public static Limit of(long maxResults) {
+        return new Limit(maxResults, DEFAULT_START_AT);
     }
 
     /**
@@ -99,7 +100,7 @@ public class Limit {
      * @throws IllegalArgumentException if maxResults or startAt is
      *         less than 1.
      */
-    public Limit of(long maxResults, long startAt) {
+    public static Limit of(long maxResults, long startAt) {
         if (startAt < 1)
             throw new IllegalArgumentException("startAt: " + startAt);
 
diff --git a/spec/src/main/asciidoc/license-efsl.adoc b/spec/src/main/asciidoc/license-efsl.adoc
index 2f1b9374..9b5a8f6e 100644
--- a/spec/src/main/asciidoc/license-efsl.adoc
+++ b/spec/src/main/asciidoc/license-efsl.adoc
@@ -1,5 +1,3 @@
-:doctype: book
-
 [subs="normal"]
 ....
 Specification: {doctitle}
@@ -11,11 +9,11 @@ Status: {revremark}
 Release: {revdate}
 ....
 
-= Copyright
+== Copyright
 
 Copyright (c) {inceptionYear} , {currentYear} Eclipse Foundation.
 
-== Eclipse Foundation Specification License
+=== Eclipse Foundation Specification License
 
 By using and/or copying this document, or the Eclipse Foundation
 document from which this statement is linked, you (the licensee) agree
@@ -55,7 +53,7 @@ The notice is:
 document includes material copied from or derived from [title and URI
 of the Eclipse Foundation specification document]."
 
-== Disclaimers
+==== Disclaimers
 
 THIS DOCUMENT IS PROVIDED &quot;AS IS,&quot; AND THE COPYRIGHT
 HOLDERS AND THE ECLIPSE FOUNDATION MAKE NO REPRESENTATIONS OR
@@ -75,4 +73,4 @@ The name and trademarks of the copyright holders or the Eclipse
 Foundation may NOT be used in advertising or publicity pertaining to
 this document or its contents without specific, written prior
 permission. Title to copyright in this document will at all times
-remain with copyright holders.
+remain with copyright holders.
\ No newline at end of file


Test patch:
diff --git a/api/src/test/java/jakarta/data/repository/LimitTest.java b/api/src/test/java/jakarta/data/repository/LimitTest.java
new file mode 100644
index 00000000..13f8e4f0
--- /dev/null
+++ b/api/src/test/java/jakarta/data/repository/LimitTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2022 Contributors to the Eclipse Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+package jakarta.data.repository;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class LimitTest {
+
+    @Test
+    public void shouldReturnErrorWhenMaxResultsIsNegative() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> Limit.of(-1));
+    }
+
+    @Test
+    public void shouldReturnErrorWhenMaxResultsIsZero() {
+        Assertions.assertThrows(IllegalArgumentException.class, () -> Limit.of(0));
+    }
+
+    @Test
+    public void shouldReturnErrorWhenStartAtIsNegative(){
+        Assertions.assertThrows(IllegalArgumentException.class, () -> Limit.of(1, -1));
+    }
+
+    @Test
+    public void shouldReturnErrorWhenStartAtIsZero(){
+        Assertions.assertThrows(IllegalArgumentException.class, () -> Limit.of(1, 0));
+    }
+    @Test
+    public void shouldCreateLimitWithDefaultStartAt() {
+        Limit limit = Limit.of(10);
+        Assertions.assertNotNull(limit);
+        Assertions.assertEquals(10L, limit.maxResults());
+        Assertions.assertEquals(1L, limit.startAt());
+    }
+
+    @Test
+    public void shouldCreateLimit() {
+        Limit limit = Limit.of(10, 2);
+        Assertions.assertNotNull(limit);
+        Assertions.assertEquals(10L, limit.maxResults());
+        Assertions.assertEquals(2L, limit.startAt());
+    }
+}
\ No newline at end of file