Path: blob/master/test/jdk/java/beans/XMLDecoder/spec/TestNew.java
41155 views
/*1* Copyright (c) 2008, 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* @summary Tests <new> element26* @run main/othervm -Djava.security.manager=allow TestNew27* @author Sergey Malenkov28*/2930import java.beans.XMLDecoder;31import java.util.ArrayList;32import java.util.List;3334public final class TestNew extends AbstractTest {35public static final String XML36= "<java>\n"37+ " <new class=\"TestNew\"/>\n"38+ " <new class=\"TestNew\">\n"39+ " <null/>\n"40+ " </new>\n"41+ " <new class=\"TestNew\">\n"42+ " <string>single</string>\n"43+ " </new>\n"44+ " <new class=\"TestNew\">\n"45+ " <string>first</string>\n"46+ " <string>second</string>\n"47+ " <string>third</string>\n"48+ " </new>\n"49+ "</java>";5051public static void main(String[] args) {52new TestNew().test(true);53}5455private List<String> list;5657public TestNew(String...messages) {58if (messages != null) {59this.list = new ArrayList<String>();60for (String message : messages) {61this.list.add(message);62}63}64}6566@Override67public boolean equals(Object object) {68if (object instanceof TestNew) {69TestNew test = (TestNew) object;70return (test.list == null)71? this.list == null72: test.list.equals(this.list);73}74return false;75}7677@Override78protected void validate(XMLDecoder decoder) {79validate(decoder.readObject());80validate(decoder.readObject(), null);81validate(decoder.readObject(), "single");82validate(decoder.readObject(), "first", "second", "third");83}8485private static void validate(Object object, String...messages) {86if (!object.equals(new TestNew(messages))) {87throw new Error("expected object");88}89}90}919293