Path: blob/master/test/jdk/java/io/FilePermission/SpecTests.java
41149 views
/*1* Copyright (c) 2005, 2019, 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 4955804 823040726* @summary Tests for FilePermission constructor spec for null,27* empty and misformated String parameters28*/2930import java.io.*;3132public class SpecTests {3334public static void main(String args[]) throws Exception {35String ILE = "java.lang.IllegalArgumentException";36String NPE = "java.lang.NullPointerException";3738String names[] = {"", null, "foo", "foo", "foo", "foo", "foo"};39String actions[] = {"read", "read", "", null, "junk",40"read,write,execute,delete,rename",41",read"};42String exps[] = { null, NPE, ILE, ILE, ILE, ILE, ILE };4344FilePermission permit;45for (int i = 0; i < names.length; i++) {46try {47permit = new FilePermission(names[i], actions[i]);48} catch (Exception e) {49if (exps[i] == null) {50throw e;51} else if (!((e.getClass().getName()).equals(exps[i]))) {52throw new Exception("Expecting: " + exps[i] +53" for name:" + names[i] +54" actions:" + actions[i]);55} else {56System.out.println(names[i] + ", [" + actions[i] + "] " +57"resulted in " + exps[i] + " as Expected");58continue;59}60}61if (exps[i] == null) {62System.out.println(names[i] + ", [" + actions[i] + "] " +63"resulted in No Exception as Expected");64} else {65throw new Exception("Expecting: " + exps[i] +66" for name:" + names[i] +67" actions:" + actions[i]);68}69}70}71}727374