Path: blob/master/test/jdk/javax/management/loading/MLetInternalsTest.java
41149 views
/*1* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.lang.reflect.Method;24import java.util.HashMap;25import java.util.Map;26import javax.management.loading.MLet;27import org.testng.annotations.Test;28import org.testng.annotations.BeforeClass;29import org.testng.annotations.BeforeTest;3031import static org.testng.Assert.*;3233/*34* @test35* @bug 805808936* @summary Tests various internal functions provided by MLet for correctness37* @author Jaroslav Bachorik38* @modules java.management/javax.management.loading:open39* @run testng MLetInternalsTest40*/41public class MLetInternalsTest {42private final static String CONSTRUCT_PARAMETER = "constructParameter";4344private final static Map<String, Method> testedMethods = new HashMap<>();4546@BeforeClass47public static void setupClass() {48testedMethods.clear();49try {50Method m = MLet.class.getDeclaredMethod(51CONSTRUCT_PARAMETER,52String.class, String.class53);54m.setAccessible(true);5556testedMethods.put(CONSTRUCT_PARAMETER, m);57} catch (Exception ex) {58throw new Error(ex);59}60}6162private MLet mlet;6364@BeforeTest65public void setupTest() {66mlet = new MLet();67}6869@Test70public void testConstructParameter() throws Exception {71assertEquals(constructParameter("120", "int"), 120);72assertEquals(constructParameter("120", "java.lang.Integer"), Integer.valueOf(120));73assertEquals(constructParameter("120", "long"), 120L);74assertEquals(constructParameter("120", "java.lang.Long"), Long.valueOf(120));75assertEquals(constructParameter("120.0", "float"), 120.0f);76assertEquals(constructParameter("120.0", "java.lang.Float"), Float.valueOf(120.0f));77assertEquals(constructParameter("120.0", "double"), 120.0d);78assertEquals(constructParameter("120", "java.lang.Double"), Double.valueOf(120d));79assertEquals(constructParameter("120", "java.lang.String"), "120");80assertEquals(constructParameter("120", "byte"), (byte)120);81assertEquals(constructParameter("120", "java.lang.Byte"), (byte)120);82assertEquals(constructParameter("120", "short"), (short)120);83assertEquals(constructParameter("120", "java.lang.Short"), (short)120);84assertEquals(constructParameter("true", "boolean"), true);85assertEquals(constructParameter("true", "java.lang.Boolean"), Boolean.valueOf(true));86}8788private Object constructParameter(String param, String type) throws Exception {89return testedMethods.get(CONSTRUCT_PARAMETER).invoke(mlet, param, type);90}91}929394