jdk/test/javax/management/loading/MLetInternalsTest.java
changeset 26484 871db348e647
child 30376 2ccf2cf7ea48
equal deleted inserted replaced
26483:c0920178d0be 26484:871db348e647
       
     1 /*
       
     2  * Copyright (c) 2014, 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 import java.lang.reflect.Method;
       
    25 import java.util.HashMap;
       
    26 import java.util.Map;
       
    27 import javax.management.loading.MLet;
       
    28 import org.testng.annotations.Test;
       
    29 import org.testng.annotations.BeforeClass;
       
    30 import org.testng.annotations.BeforeTest;
       
    31 
       
    32 import static org.testng.Assert.*;
       
    33 
       
    34 /*
       
    35  * @test
       
    36  * @bug 8058089
       
    37  * @summary Tests various internal functions provided by MLet for correctness
       
    38  * @author Jaroslav Bachorik
       
    39  * @run testng MLetInternalsTest
       
    40  */
       
    41 public class MLetInternalsTest {
       
    42     private final static String CONSTRUCT_PARAMETER = "constructParameter";
       
    43 
       
    44     private final static Map<String, Method> testedMethods = new HashMap<>();
       
    45 
       
    46     @BeforeClass
       
    47     public static void setupClass() {
       
    48         testedMethods.clear();
       
    49         try {
       
    50             Method m = MLet.class.getDeclaredMethod(
       
    51                     CONSTRUCT_PARAMETER,
       
    52                     String.class, String.class
       
    53             );
       
    54             m.setAccessible(true);
       
    55 
       
    56             testedMethods.put(CONSTRUCT_PARAMETER, m);
       
    57         } catch (Exception ex) {
       
    58             throw new Error(ex);
       
    59         }
       
    60     }
       
    61 
       
    62     private MLet mlet;
       
    63 
       
    64     @BeforeTest
       
    65     public void setupTest() {
       
    66         mlet = new MLet();
       
    67     }
       
    68 
       
    69     @Test
       
    70     public void testConstructParameter() throws Exception {
       
    71         assertEquals(constructParameter("120", "int"), 120);
       
    72         assertEquals(constructParameter("120", "java.lang.Integer"), Integer.valueOf(120));
       
    73         assertEquals(constructParameter("120", "long"), 120L);
       
    74         assertEquals(constructParameter("120", "java.lang.Long"), Long.valueOf(120));
       
    75         assertEquals(constructParameter("120.0", "float"), 120.0f);
       
    76         assertEquals(constructParameter("120.0", "java.lang.Float"), Float.valueOf(120.0f));
       
    77         assertEquals(constructParameter("120.0", "double"), 120.0d);
       
    78         assertEquals(constructParameter("120", "java.lang.Double"), Double.valueOf(120d));
       
    79         assertEquals(constructParameter("120", "java.lang.String"), "120");
       
    80         assertEquals(constructParameter("120", "byte"), (byte)120);
       
    81         assertEquals(constructParameter("120", "java.lang.Byte"), (byte)120);
       
    82         assertEquals(constructParameter("120", "short"), (short)120);
       
    83         assertEquals(constructParameter("120", "java.lang.Short"), (short)120);
       
    84         assertEquals(constructParameter("true", "boolean"), true);
       
    85         assertEquals(constructParameter("true", "java.lang.Boolean"), Boolean.valueOf(true));
       
    86     }
       
    87 
       
    88     private Object constructParameter(String param, String type) throws Exception {
       
    89         return testedMethods.get(CONSTRUCT_PARAMETER).invoke(mlet, param, type);
       
    90     }
       
    91 }