Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLDecoder/spec/TestNew.java
38821 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* @author Sergey Malenkov27*/2829import java.beans.XMLDecoder;30import java.util.ArrayList;31import java.util.List;3233public final class TestNew extends AbstractTest {34public static final String XML35= "<java>\n"36+ " <new class=\"TestNew\"/>\n"37+ " <new class=\"TestNew\">\n"38+ " <null/>\n"39+ " </new>\n"40+ " <new class=\"TestNew\">\n"41+ " <string>single</string>\n"42+ " </new>\n"43+ " <new class=\"TestNew\">\n"44+ " <string>first</string>\n"45+ " <string>second</string>\n"46+ " <string>third</string>\n"47+ " </new>\n"48+ "</java>";4950public static void main(String[] args) {51new TestNew().test(true);52}5354private List<String> list;5556public TestNew(String...messages) {57if (messages != null) {58this.list = new ArrayList<String>();59for (String message : messages) {60this.list.add(message);61}62}63}6465@Override66public boolean equals(Object object) {67if (object instanceof TestNew) {68TestNew test = (TestNew) object;69return (test.list == null)70? this.list == null71: test.list.equals(this.list);72}73return false;74}7576@Override77protected void validate(XMLDecoder decoder) {78validate(decoder.readObject());79validate(decoder.readObject(), null);80validate(decoder.readObject(), "single");81validate(decoder.readObject(), "first", "second", "third");82}8384private static void validate(Object object, String...messages) {85if (!object.equals(new TestNew(messages))) {86throw new Error("expected object");87}88}89}909192