UnionTest.java revision 2362
0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6273752
0N/A * @summary Test ImmutableDescriptor.union
0N/A * @author Eamonn McManus
0N/A * @run clean UnionTest
0N/A * @run build UnionTest
0N/A * @run main UnionTest
0N/A */
0N/A
0N/Aimport java.util.Collections;
0N/Aimport javax.management.Descriptor;
0N/Aimport javax.management.ImmutableDescriptor;
0N/Aimport static javax.management.ImmutableDescriptor.union;
0N/Aimport static javax.management.ImmutableDescriptor.EMPTY_DESCRIPTOR;
0N/Aimport javax.management.modelmbean.DescriptorSupport;
0N/A
0N/Apublic class UnionTest {
0N/A public static void main(String[] args) throws Exception {
0N/A ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
0N/A DescriptorSupport mutableEmpty = new DescriptorSupport();
0N/A
0N/A checkEmpty(union());
0N/A checkEmpty(union(immutableEmpty));
0N/A checkEmpty(union(mutableEmpty));
0N/A checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
0N/A checkEmpty(union(null, immutableEmpty, null));
0N/A
0N/A ImmutableDescriptor immutableNumbers =
0N/A new ImmutableDescriptor(new String[] {"one", "two", "three"},
0N/A new Object[] {1, 2, 3});
0N/A final String[] noNames = null;
0N/A DescriptorSupport mutableNumbers =
0N/A new DescriptorSupport(immutableNumbers.getFieldNames(),
0N/A immutableNumbers.getFieldValues(noNames));
0N/A ImmutableDescriptor immutableOne =
0N/A new ImmutableDescriptor(Collections.singletonMap("one", 1));
0N/A DescriptorSupport mutableOne =
0N/A new DescriptorSupport(new String[] {"one"}, new Object[] {1});
0N/A ImmutableDescriptor immutableTwo =
0N/A new ImmutableDescriptor(Collections.singletonMap("two", 2));
0N/A DescriptorSupport mutableTwo =
0N/A new DescriptorSupport(new String[] {"two"}, new Object[] {2});
0N/A ImmutableDescriptor immutableOneTwo =
0N/A new ImmutableDescriptor(new String[] {"one", "two"},
0N/A new Object[] {1, 2});
0N/A
0N/A
0N/A checkEqual(union(immutableNumbers), immutableNumbers);
0N/A checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
0N/A checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
0N/A checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
0N/A mutableNumbers, immutableOne), immutableNumbers);
0N/A checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
0N/A immutableNumbers);
0N/A checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
0N/A checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
0N/A checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);
0N/A
0N/A if (failure != null)
0N/A throw new Exception("TEST FAILED: " + failure);
0N/A System.out.println("TEST PASSED");
0N/A }
0N/A
0N/A private static void checkEmpty(ImmutableDescriptor d) {
0N/A if (d != EMPTY_DESCRIPTOR) {
0N/A failure = "Union of empty descriptors should be " +
0N/A "ImmutableDescriptor.EMPTY";
0N/A System.err.println("FAILED: " + failure);
0N/A Thread.dumpStack();
0N/A }
0N/A }
0N/A
0N/A private static void checkEqual(ImmutableDescriptor d,
0N/A ImmutableDescriptor e) {
0N/A if (d != e) {
0N/A failure = "Union should produce one of its arguments but does not";
0N/A System.err.println("FAILED: " + failure);
0N/A Thread.dumpStack();
0N/A }
0N/A }
0N/A
0N/A private static void checkEquivalent(ImmutableDescriptor d,
0N/A ImmutableDescriptor e) {
0N/A if (!d.equals(e)) {
0N/A failure = "Union produced this: " + d + "; but should have " +
0N/A "produced this: " + e;
0N/A System.err.println("FAILED: " + failure);
0N/A Thread.dumpStack();
0N/A }
0N/A }
0N/A
0N/A private static String failure;
0N/A}