1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package test.java.util.Properties; 25 26 import java.io.ByteArrayOutputStream; 27 import java.io.IOException; 28 import java.util.Properties; 29 import org.testng.Assert; 30 31 import org.testng.annotations.DataProvider; 32 import org.testng.annotations.Test; 33 34 /* 35 * @test 36 * @bug 8252354 37 * @run testng CompatibilityTest 38 * @summary Verify compatibility. 39 */ 40 public class CompatibilityTest { 41 @DataProvider(name = "entries") getEntries()42 public Object[][] getEntries() throws IOException { 43 return new Object[][]{ 44 {8, 238923}, 45 {1.1, 1.1}, 46 {new Object(), "Value"}, 47 {"Key", new Object()}, 48 }; 49 } 50 51 /** 52 * Verifies that a ClassCastException is thrown as specified by the 53 * {@code storeToXML} method. 54 * @param key the key 55 * @param value the value 56 * @throws IOException 57 */ 58 // Android-changed: Android is using Java 7's version of storeToXML, 59 // which does not throw. 60 // @Test(dataProvider = "entries") 61 @Test(dataProvider = "entries", enabled = false) testThrows(Object key, Object value)62 void testThrows(Object key, Object value) throws IOException { 63 Assert.assertThrows(ClassCastException.class, () -> storeToXML(key, value)); 64 } 65 storeToXML(Object key, Object value)66 void storeToXML(Object key, Object value) throws IOException { 67 ByteArrayOutputStream os = new ByteArrayOutputStream(); 68 Properties pr = new Properties(); 69 pr.put(key, value); 70 pr.storeToXML(os, "Test", "UTF-8"); 71 } 72 } 73