VarHandleTestAccessModeMethodNames.java revision 14910:9d57bb03c86c
1231200Smm/*
2231200Smm * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3231200Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4231200Smm *
5231200Smm * This code is free software; you can redistribute it and/or modify it
6231200Smm * under the terms of the GNU General Public License version 2 only, as
7231200Smm * published by the Free Software Foundation.
8231200Smm *
9231200Smm * This code is distributed in the hope that it will be useful, but WITHOUT
10231200Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11231200Smm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12231200Smm * version 2 for more details (a copy is included in the LICENSE file that
13231200Smm * accompanied this code).
14231200Smm *
15231200Smm * You should have received a copy of the GNU General Public License version
16231200Smm * 2 along with this work; if not, write to the Free Software Foundation,
17231200Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18231200Smm *
19231200Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20231200Smm * or visit www.oracle.com if you need additional information or have any
21231200Smm * questions.
22231200Smm */
23231200Smm
24231200Smm/*
25231200Smm * @test
26231200Smm * @run testng VarHandleTestAccessModeMethodNames
27231200Smm */
28231200Smm
29231200Smmimport org.testng.annotations.DataProvider;
30231200Smmimport org.testng.annotations.Test;
31231200Smm
32231200Smmimport java.lang.invoke.VarHandle;
33231200Smmimport java.util.stream.Stream;
34231200Smm
35231200Smmimport static org.testng.Assert.assertEquals;
36231200Smm
37232153Smmpublic class VarHandleTestAccessModeMethodNames {
38232153Smm
39232153Smm    @DataProvider
40231200Smm    public static Object[][] accessModesProvider() {
41231200Smm        return Stream.of(VarHandle.AccessMode.values()).
42231200Smm                map(am -> new Object[]{am}).
43231200Smm                toArray(Object[][]::new);
44232153Smm    }
45232153Smm
46231200Smm
47231200Smm    @Test(dataProvider = "accessModesProvider")
48231200Smm    public void testMethodName(VarHandle.AccessMode am) {
49231200Smm        assertEquals(am.methodName(), toMethodName(am.name()));
50231200Smm    }
51231200Smm
52231200Smm    private static String toMethodName(String name) {
53231200Smm        StringBuilder s = new StringBuilder(name.toLowerCase());
54231200Smm        int i;
55231200Smm        while ((i = s.indexOf("_")) !=  -1) {
56231200Smm            s.deleteCharAt(i);
57231200Smm            s.setCharAt(i, Character.toUpperCase(s.charAt(i)));
58231200Smm        }
59231200Smm        return s.toString();
60231200Smm    }
61231200Smm}
62231200Smm