1+ /*
2+ * Copyright 2025 GWT Project Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+ * use this file except in compliance with the License. You may obtain a copy of
6+ * the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ * License for the specific language governing permissions and limitations under
14+ * the License.
15+ */
16+ package com .google .gwt .emultest .java17 .util ;
17+
18+ import com .google .gwt .emultest .java .util .EmulTestBase ;
19+
20+ import java .util .Objects ;
21+
22+ /**
23+ * Tests {@link Objects} additions up to Java 17 (checkIndex* is part of Java 16).
24+ */
25+ public class ObjectsTest extends EmulTestBase {
26+
27+ public void testCheckIndex () {
28+ assertEquals (50000000000L , Objects .checkIndex (50000000000L , 100000000000L ));
29+ assertThrows (IndexOutOfBoundsException .class ,
30+ () -> Objects .checkIndex (-50000000000L , 50000000000L ));
31+ assertThrows (IndexOutOfBoundsException .class ,
32+ () -> Objects .checkIndex (100000000000L , 50000000000L ));
33+ assertThrows (IndexOutOfBoundsException .class ,
34+ () -> Objects .checkIndex (50000000000L , 50000000000L ));
35+ }
36+
37+ public void testCheckFromToIndex () {
38+ assertEquals (50000000000L ,
39+ Objects .checkFromToIndex (50000000000L , 70000000000L , 100000000000L ));
40+ assertEquals (0L , Objects .checkFromToIndex (0 , 100000000000L , 100000000000L ));
41+ assertThrows (IndexOutOfBoundsException .class ,
42+ () -> Objects .checkFromToIndex (-50000000000L , 10000000000L , 50000000000L ));
43+ assertThrows (IndexOutOfBoundsException .class ,
44+ () -> Objects .checkFromToIndex (100000000000L , 10000000000L , 50000000000L ));
45+ assertThrows (IndexOutOfBoundsException .class ,
46+ () -> Objects .checkFromToIndex (10000000000L , 100000000000L , 50000000000L ));
47+ }
48+
49+ public void testCheckFromIndexSize () {
50+ assertEquals (50000000000L ,
51+ Objects .checkFromIndexSize (50000000000L , 20000000000L , 100000000000L ));
52+ assertEquals (0L , Objects .checkFromIndexSize (0 , 100000000000L , 100000000000L ));
53+ assertThrows (IndexOutOfBoundsException .class ,
54+ () -> Objects .checkFromIndexSize (-50000000000L , 10000000000L , 50000000000L ));
55+ assertThrows (IndexOutOfBoundsException .class ,
56+ () -> Objects .checkFromIndexSize (100000000000L , 10000000000L , 50000000000L ));
57+ assertThrows (IndexOutOfBoundsException .class ,
58+ () -> Objects .checkFromIndexSize (10000000000L , 100000000000L , 50000000000L ));
59+ assertThrows (IndexOutOfBoundsException .class ,
60+ () -> Objects .checkFromIndexSize (10000000000L , -50000000000L , 50000000000L ));
61+ }
62+
63+ }
0 commit comments