Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Arrays/StreamAndSpliterator.java
41152 views
1
/*
2
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8037857
27
* @summary tests for stream and spliterator factory methods
28
* @run testng StreamAndSpliterator
29
*/
30
31
import org.testng.annotations.Test;
32
33
import java.util.Arrays;
34
import java.util.Spliterators;
35
36
import org.testng.Assert.ThrowingRunnable;
37
38
import static org.testng.Assert.assertThrows;
39
40
public class StreamAndSpliterator {
41
@Test
42
public void testStreamNPEs() {
43
assertThrowsNPE(() -> Arrays.stream((int[]) null, 0, 0));
44
assertThrowsNPE(() -> Arrays.stream((long[]) null, 0, 0));
45
assertThrowsNPE(() -> Arrays.stream((double[]) null, 0, 0));
46
assertThrowsNPE(() -> Arrays.stream((String[]) null, 0, 0));
47
}
48
49
@Test
50
public void testStreamAIOBEs() {
51
// origin > fence
52
assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, 1, 0));
53
assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, 1, 0));
54
assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, 1, 0));
55
assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, 1, 0));
56
57
// bad origin
58
assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, -1, 0));
59
assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, -1, 0));
60
assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, -1, 0));
61
assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, -1, 0));
62
63
// bad fence
64
assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, 0, 1));
65
assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, 0, 1));
66
assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, 0, 1));
67
assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, 0, 1));
68
}
69
70
71
@Test
72
public void testSpliteratorNPEs() {
73
assertThrowsNPE(() -> Arrays.spliterator((int[]) null, 0, 0));
74
assertThrowsNPE(() -> Arrays.spliterator((long[]) null, 0, 0));
75
assertThrowsNPE(() -> Arrays.spliterator((double[]) null, 0, 0));
76
assertThrowsNPE(() -> Arrays.spliterator((String[]) null, 0, 0));
77
}
78
79
@Test
80
public void testSpliteratorAIOBEs() {
81
// origin > fence
82
assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, 1, 0));
83
assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, 1, 0));
84
assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, 1, 0));
85
assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, 1, 0));
86
87
// bad origin
88
assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, -1, 0));
89
assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, -1, 0));
90
assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, -1, 0));
91
assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, -1, 0));
92
93
// bad fence
94
assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, 0, 1));
95
assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, 0, 1));
96
assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, 0, 1));
97
assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, 0, 1));
98
}
99
100
101
@Test
102
public void testSpliteratorNPEsFromSpliterators() {
103
assertThrowsNPE(() -> Spliterators.spliterator((int[]) null, 0, 0, 0));
104
assertThrowsNPE(() -> Spliterators.spliterator((long[]) null, 0, 0, 0));
105
assertThrowsNPE(() -> Spliterators.spliterator((double[]) null, 0, 0, 0));
106
assertThrowsNPE(() -> Spliterators.spliterator((String[]) null, 0, 0, 0));
107
}
108
109
@Test
110
public void testSpliteratorAIOBEsFromSpliterators() {
111
// origin > fence
112
assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, 1, 0, 0));
113
assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, 1, 0, 0));
114
assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, 1, 0, 0));
115
assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, 1, 0, 0));
116
117
// bad origin
118
assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, -1, 0, 0));
119
assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, -1, 0, 0));
120
assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, -1, 0, 0));
121
assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, -1, 0, 0));
122
123
// bad fence
124
assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, 0, 1, 0));
125
assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, 0, 1, 0));
126
assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, 0, 1, 0));
127
assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, 0, 1, 0));
128
}
129
130
void assertThrowsNPE(ThrowingRunnable r) {
131
assertThrows(NullPointerException.class, r);
132
}
133
134
void assertThrowsAIOOB(ThrowingRunnable r) {
135
assertThrows(ArrayIndexOutOfBoundsException.class, r);
136
}
137
}
138
139