Path: blob/master/test/jdk/java/lang/ToString.java
41144 views
/*1* Copyright (c) 2000, 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 403176226* @summary Test the primitive wrappers static toString()27* @key randomness28*/2930import java.util.Random;3132public class ToString {3334private static Random generator = new Random();3536public static void main(String args[]) throws Exception {37// boolean wrapper38boolean b = false;39Boolean B = new Boolean(b);40if (!B.toString().equals(Boolean.toString(b)))41throw new RuntimeException("Boolean wrapper toString() failure.");42b = true;43B = new Boolean(b);44if (!B.toString().equals(Boolean.toString(b)))45throw new RuntimeException("Boolean wrapper toString() failure.");4647// char wrapper48for(int x=0; x<100; x++) {49char c = (char)generator.nextInt();50Character C = new Character(c);51if (!C.toString().equals(Character.toString(c)))52throw new RuntimeException("Character wrapper toString() failure.");53}5455// byte wrapper56for(int x=0; x<100; x++) {57byte y = (byte)generator.nextInt();58Byte Y = new Byte(y);59if (!Y.toString().equals(Byte.toString(y)))60throw new RuntimeException("Byte wrapper toString() failure.");61}6263// short wrapper64for(int x=0; x<100; x++) {65short s = (short)generator.nextInt();66Short S = new Short(s);67if (!S.toString().equals(Short.toString(s)))68throw new RuntimeException("Short wrapper toString() failure.");69}7071// int wrapper72for(int x=0; x<100; x++) {73int i = generator.nextInt();74Integer I = new Integer(i);75if (!I.toString().equals(Integer.toString(i)))76throw new RuntimeException("Integer wrapper toString() failure.");77}7879// long wrapper80for(int x=0; x<100; x++) {81long l = generator.nextLong();82Long L = new Long(l);83if (!L.toString().equals(Long.toString(l)))84throw new RuntimeException("Long wrapper toString() failure.");85}8687// float wrapper88for(int x=0; x<100; x++) {89float f = generator.nextFloat();90Float F = new Float(f);91if (!F.toString().equals(Float.toString(f)))92throw new RuntimeException("Float wrapper toString() failure.");93}9495// double wrapper96for(int x=0; x<100; x++) {97double d = generator.nextDouble();98Double D = new Double(d);99if (!D.toString().equals(Double.toString(d)))100throw new RuntimeException("Double wrapper toString() failure.");101}102103}104}105106107