Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/invoke/MethodHandlesCollectArgsTest.java
41149 views
1
/*
2
* Copyright (c) 2021, 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
/* @test
25
* @bug 8259922
26
* @run testng/othervm MethodHandlesCollectArgsTest
27
*/
28
29
import org.testng.annotations.Test;
30
import org.testng.annotations.DataProvider;
31
32
import java.lang.invoke.MethodHandle;
33
import java.lang.invoke.MethodHandles;
34
import java.lang.invoke.MethodType;
35
import static java.lang.invoke.MethodType.methodType;
36
37
import static org.testng.Assert.*;
38
39
public class MethodHandlesCollectArgsTest {
40
41
private static final MethodHandle TARGET_II_I = MethodHandles.empty(methodType(int.class, int.class, int.class));
42
private static final MethodHandle TARGET__V = MethodHandles.empty(methodType(void.class));
43
private static final MethodHandle FILTER_INT = MethodHandles.empty(methodType(int.class, String.class));
44
private static final MethodHandle FILTER_VOID = MethodHandles.empty(methodType(void.class, String.class));
45
46
@DataProvider(name = "illegalPos")
47
public static Object[][] illegalPos() {
48
return new Object[][] {
49
{TARGET_II_I, 2, FILTER_INT},
50
{TARGET_II_I, 3, FILTER_VOID},
51
{TARGET_II_I, -1, FILTER_INT},
52
{TARGET_II_I, -1, FILTER_VOID},
53
{TARGET__V, 0, FILTER_INT},
54
{TARGET__V, 1, FILTER_VOID},
55
{TARGET__V, -1, FILTER_VOID},
56
{TARGET__V, -1, FILTER_VOID}
57
};
58
}
59
60
@DataProvider(name = "validPos")
61
public static Object[][] validPos() {
62
return new Object[][] {
63
{TARGET_II_I, 0, FILTER_INT, methodType(int.class, String.class, int.class)},
64
{TARGET_II_I, 1, FILTER_INT, methodType(int.class, int.class, String.class)},
65
{TARGET_II_I, 0, FILTER_VOID, methodType(int.class, String.class, int.class, int.class)},
66
{TARGET_II_I, 1, FILTER_VOID, methodType(int.class, int.class, String.class, int.class)},
67
{TARGET_II_I, 2, FILTER_VOID, methodType(int.class, int.class, int.class, String.class)},
68
{TARGET__V, 0, FILTER_VOID, methodType(void.class, String.class)}
69
};
70
}
71
72
@Test(dataProvider="illegalPos", expectedExceptions = {IllegalArgumentException.class})
73
public void illegalPosition(MethodHandle target, int position, MethodHandle filter) {
74
MethodHandles.collectArguments(target, position, filter);
75
}
76
77
@Test(dataProvider="validPos")
78
public void legalPosition(MethodHandle target, int position, MethodHandle filter, MethodType expectedType) {
79
MethodHandle result = MethodHandles.collectArguments(target, position, filter);
80
assertEquals(result.type(), expectedType);
81
}
82
}
83
84