Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/descriptor/UnionTest.java
38838 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 627375226* @summary Test ImmutableDescriptor.union27* @author Eamonn McManus28* @run clean UnionTest29* @run build UnionTest30* @run main UnionTest31*/3233import java.util.Collections;34import javax.management.Descriptor;35import javax.management.ImmutableDescriptor;36import static javax.management.ImmutableDescriptor.union;37import static javax.management.ImmutableDescriptor.EMPTY_DESCRIPTOR;38import javax.management.modelmbean.DescriptorSupport;3940public class UnionTest {41public static void main(String[] args) throws Exception {42ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();43DescriptorSupport mutableEmpty = new DescriptorSupport();4445checkEmpty(union());46checkEmpty(union(immutableEmpty));47checkEmpty(union(mutableEmpty));48checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));49checkEmpty(union(null, immutableEmpty, null));5051ImmutableDescriptor immutableNumbers =52new ImmutableDescriptor(new String[] {"one", "two", "three"},53new Object[] {1, 2, 3});54final String[] noNames = null;55DescriptorSupport mutableNumbers =56new DescriptorSupport(immutableNumbers.getFieldNames(),57immutableNumbers.getFieldValues(noNames));58ImmutableDescriptor immutableOne =59new ImmutableDescriptor(Collections.singletonMap("one", 1));60DescriptorSupport mutableOne =61new DescriptorSupport(new String[] {"one"}, new Object[] {1});62ImmutableDescriptor immutableTwo =63new ImmutableDescriptor(Collections.singletonMap("two", 2));64DescriptorSupport mutableTwo =65new DescriptorSupport(new String[] {"two"}, new Object[] {2});66ImmutableDescriptor immutableOneTwo =67new ImmutableDescriptor(new String[] {"one", "two"},68new Object[] {1, 2});697071checkEqual(union(immutableNumbers), immutableNumbers);72checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);73checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);74checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,75mutableNumbers, immutableOne), immutableNumbers);76checkEqual(union(immutableOne, immutableTwo, immutableNumbers),77immutableNumbers);78checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);79checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);80checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);8182if (failure != null)83throw new Exception("TEST FAILED: " + failure);84System.out.println("TEST PASSED");85}8687private static void checkEmpty(ImmutableDescriptor d) {88if (d != EMPTY_DESCRIPTOR) {89failure = "Union of empty descriptors should be " +90"ImmutableDescriptor.EMPTY";91System.err.println("FAILED: " + failure);92Thread.dumpStack();93}94}9596private static void checkEqual(ImmutableDescriptor d,97ImmutableDescriptor e) {98if (d != e) {99failure = "Union should produce one of its arguments but does not";100System.err.println("FAILED: " + failure);101Thread.dumpStack();102}103}104105private static void checkEquivalent(ImmutableDescriptor d,106ImmutableDescriptor e) {107if (!d.equals(e)) {108failure = "Union produced this: " + d + "; but should have " +109"produced this: " + e;110System.err.println("FAILED: " + failure);111Thread.dumpStack();112}113}114115private static String failure;116}117118119