Path: blob/master/test/jdk/javax/management/ObjectInstance/ToStringMethodTest.java
41149 views
/*1* Copyright (c) 2004, 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*/2223/*24* @test25* @bug 508008326* @summary Test new added method "toString"27* @author Shanliang JIANG28*29* @run clean ToStringMethodTest30* @run build ToStringMethodTest31* @run main ToStringMethodTest32*/3334import javax.management.*;3536public class ToStringMethodTest {37public static void main(String[] args) throws Exception {3839// for ObjectInstance class40System.out.println(">>> Test on the method \"toString\" of the ObjectInstance class.");4142final ObjectName on = new ObjectName(":key=me");43final String className = "Unknown";44final ObjectInstance oi = new ObjectInstance(on, className);4546final String expected = className+"["+on.toString()+"]";4748if (!expected.equals(oi.toString())) {49throw new RuntimeException("The test failed on the method \"toString\" "+50"of the ObjectInstance class, expected to get "+51expected+", but got "+oi.toString());52}5354// for Attribute class55System.out.println(">>> Test on the method \"toString\" of the Attribute class.");56final String name = "hahaha";57final Object value = new int[0];58final String exp = name + " = " + value;5960final Attribute at = new Attribute(name, value);6162if (!exp.equals(at.toString())) {63throw new RuntimeException("The test failed on the method \"toString\" "+64"of the Attribute class, expected to get "+exp+65", but got "+at.toString());66}6768System.out.println(">>> All passed.");69}70}717273