Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/ObjectInstance/ToStringMethodTest.java
38838 views
/*1* Copyright (c) 2004, 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* @run clean ToStringMethodTest29* @run build ToStringMethodTest30* @run main ToStringMethodTest31*/3233import javax.management.*;3435public class ToStringMethodTest {36public static void main(String[] args) throws Exception {3738// for ObjectInstance class39System.out.println(">>> Test on the method \"toString\" of the ObjectInstance class.");4041final ObjectName on = new ObjectName(":key=me");42final String className = "Unknown";43final ObjectInstance oi = new ObjectInstance(on, className);4445final String expected = className+"["+on.toString()+"]";4647if (!expected.equals(oi.toString())) {48throw new RuntimeException("The test failed on the method \"toString\" "+49"of the ObjectInstance class, expected to get "+50expected+", but got "+oi.toString());51}5253// for Attribute class54System.out.println(">>> Test on the method \"toString\" of the Attribute class.");55final String name = "hahaha";56final Object value = new int[0];57final String exp = name + " = " + value;5859final Attribute at = new Attribute(name, value);6061if (!exp.equals(at.toString())) {62throw new RuntimeException("The test failed on the method \"toString\" "+63"of the Attribute class, expected to get "+exp+64", but got "+at.toString());65}6667System.out.println(">>> All passed.");68}69}707172