Path: blob/master/test/jdk/java/beans/XMLEncoder/Test7169395.java
41149 views
/*1* Copyright (c) 2012, 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 716939526* @summary Tests that array list initialized correctly27* @run main/othervm -Djava.security.manager=allow Test716939528* @author Sergey Malenkov29*/3031import java.beans.ConstructorProperties;32import java.util.ArrayList;33import java.util.Collection;34import java.util.Map;35import java.util.TreeMap;3637public class Test7169395 extends AbstractTest {3839public static void main(String[] args) {40new Test7169395().test(true);41}4243protected Object getObject() {44Container container = new Container();45container.add("test-null", null);46container.add("test-value", "value");47container.add("test-other", "other");48return container;49}5051public static class Component {5253private final Container container;54private final String name;55private String value;5657@ConstructorProperties({ "container", "name" })58public Component(Container container, String name) {59this.container = container;60this.name = name;61}6263public Container getContainer() {64return this.container;65}6667public String getName() {68return this.name;69}7071public String getValue() {72return this.value;73}7475public void setValue(String value) {76this.value = value;77}78}7980public static class Container {8182private final Map<String, Component> map = new TreeMap<String, Component>();8384public Collection<Component> getComponents() {85return new ArrayList<Component>(this.map.values());86}8788public void setComponents(Collection<Component> components) {89this.map.clear();90for (Component component : components){91this.map.put(component.getName(), component);92}93}9495public void add(String name, String value) {96Component list = new Component(this, name);97list.setValue(value);98this.map.put(name, list);99}100}101}102103104