Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/descriptor/ImmutableDescriptorSetFieldsTest.java
38839 views
/*1* Copyright (c) 2005, 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 630513926* @summary Check that calling setFields with a field names array with a27* null name in it and calling setFields with a field names array with an28* empty name in it throw the expected exceptions.29* @author Luis-Miguel Alventosa30* @run clean ImmutableDescriptorSetFieldsTest31* @run build ImmutableDescriptorSetFieldsTest32* @run main ImmutableDescriptorSetFieldsTest33*/3435import javax.management.ImmutableDescriptor;36import javax.management.RuntimeOperationsException;3738public class ImmutableDescriptorSetFieldsTest {39public static void main(String[] args) throws Exception {40boolean ok = true;41ImmutableDescriptor d = new ImmutableDescriptor("k=v");42try {43System.out.println(44"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +45"with empty name in field names array");46String fieldNames[] = { "a", "", "c" };47Object fieldValues[] = { 1, 2, 3 };48d.setFields(fieldNames, fieldValues);49System.out.println("Didn't get expected exception");50ok = false;51} catch (RuntimeOperationsException e) {52if (e.getCause() instanceof IllegalArgumentException) {53System.out.println("Got expected exception:");54ok = true;55} else {56System.out.println("Got unexpected exception:");57ok = false;58}59e.printStackTrace(System.out);60} catch (Exception e) {61System.out.println("Got unexpected exception:");62ok = false;63e.printStackTrace(System.out);64}65try {66System.out.println(67"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +68"with null name in field names array");69String fieldNames[] = { "a", null, "c" };70Object fieldValues[] = { 1, 2, 3 };71d.setFields(fieldNames, fieldValues);72System.out.println("Didn't get expected exception");73ok = false;74} catch (RuntimeOperationsException e) {75if (e.getCause() instanceof IllegalArgumentException) {76System.out.println("Got expected exception:");77ok = true;78} else {79System.out.println("Got unexpected exception:");80ok = false;81}82e.printStackTrace(System.out);83} catch (Exception e) {84System.out.println("Got unexpected exception:");85ok = false;86e.printStackTrace(System.out);87}88if (ok) {89System.out.println("TEST PASSED");90} else {91System.out.println("TEST FAILED");92throw new Exception("Got unexpected exceptions");93}94}95}969798