View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.objecttools;
18  
19  import static org.apache.juneau.commons.utils.CollectionUtils.*;
20  import static org.apache.juneau.junit.bct.BctAssertions.*;
21  import static org.junit.jupiter.api.Assertions.*;
22  
23  import org.apache.juneau.*;
24  import org.junit.jupiter.api.*;
25  
26  /**
27   * Tests the PojoPaginator class.
28   */
29  class ObjectPaginator_Test extends TestBase {
30  
31  	ObjectPaginator op = ObjectPaginator.create();
32  	BeanSession bs = BeanContext.DEFAULT_SESSION;
33  
34  	//-----------------------------------------------------------------------------------------------------------------
35  	// Null input
36  	//-----------------------------------------------------------------------------------------------------------------
37  
38  	@Test void a01_nullInput() {
39  		assertNull(op.run(bs, null, null));
40  	}
41  
42  	@Test void a02_nonCollectionInput() {
43  		assertEquals("foo", op.run(bs, "foo", PageArgs.create(1, 3)));
44  	}
45  
46  	//-----------------------------------------------------------------------------------------------------------------
47  	// Arrays
48  	//-----------------------------------------------------------------------------------------------------------------
49  
50  	@Test void b01_arrays_basic() {
51  		var in = ints(1,2,3);
52  		assertList(op.run(in, 0, 3), 1,2,3);
53  		assertList(op.run(in, 1, 3), 2,3);
54  		assertList(op.run(in, 1, 1), 2);
55  		assertList(op.run(in, 4, 1));
56  		assertList(op.run(in, 0, 0));
57  
58  		var in2 = a("1","2","3");
59  		assertList(op.run(in2, 1, 1), "2");
60  
61  		var in3 = booleans(false,true,false);
62  		assertList(op.run(in3, 1, 1), true);
63  
64  		var in4 = bytes(1,2,3);
65  		assertList(op.run(in4, 1, 1), (byte)2);
66  
67  		var in5 = chars('1','2','3');
68  		assertList(op.run(in5, 1, 1), '2');
69  
70  		var in6 = doubles(1,2,3);
71  		assertList(op.run(in6, 1, 1), (double)2);
72  
73  		var in7 = floats(1,2,3);
74  		assertList(op.run(in7, 1, 1), (float)2);
75  
76  		var in8 = longs(1,2,3);
77  		assertList(op.run(in8, 1, 1), (long)2);
78  
79  		var in9 = shorts(1,2,3);
80  		assertList(op.run(in9, 1, 1), (short)2);
81  	}
82  
83  	//-----------------------------------------------------------------------------------------------------------------
84  	// Collections
85  	//-----------------------------------------------------------------------------------------------------------------
86  
87  	@Test void c01_collections_basic() {
88  		var in = l(1,2,3);
89  		assertList(op.run(in, 0, 3), 1,2,3);
90  		assertList(op.run(in, 1, 3), 2,3);
91  		assertList(op.run(in, 1, 1), 2);
92  		assertList(op.run(in, 4, 1));
93  		assertList(op.run(in, 0, 0));
94  
95  		var in2 = set(1,2,3);
96  		assertList(op.run(in2, 0, 3), 1,2,3);
97  		assertList(op.run(in2, 1, 3), 2,3);
98  		assertList(op.run(in2, 1, 1), 2);
99  		assertList(op.run(in2, 4, 1));
100 		assertList(op.run(in2, 0, 0));
101 	}
102 }