PermissionCollectionStreamTest.java revision 12299:bbd5410f1dbe
1/* 2 * Copyright (c) 2015, 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/* @test 25 * @bug 8081678 26 * @summary Tests for stream returning methods 27 * @library ../../util/stream/bootlib 28 * @build java.util.stream.OpTestCase 29 * @run testng/othervm PermissionCollectionStreamTest 30 */ 31 32import org.testng.annotations.DataProvider; 33import org.testng.annotations.Test; 34 35import java.io.FilePermission; 36import java.security.Permission; 37import java.security.PermissionCollection; 38import java.util.Collection; 39import java.util.Collections; 40import java.util.function.Supplier; 41import java.util.stream.OpTestCase; 42import java.util.stream.Stream; 43import java.util.stream.TestData; 44 45public class PermissionCollectionStreamTest extends OpTestCase { 46 47 @DataProvider 48 public static Object[][] permissions() { 49 return new Object[][]{ 50 { 51 "FilePermission", 52 new Permission[]{ 53 new FilePermission("/home/foobar", "read"), 54 new FilePermission("/home/foo", "write"), 55 new FilePermission("/home/foobar", "read,write"), 56 } 57 }, 58 }; 59 } 60 61 62 private PermissionCollection create(Permission[] pa) { 63 PermissionCollection pc = pa[0].newPermissionCollection(); 64 for (Permission p : pa) { 65 pc.add(p); 66 } 67 return pc; 68 } 69 70 @Test(dataProvider = "permissions") 71 public void testElementsAsStream(String description, Permission[] pa) { 72 PermissionCollection pc = create(pa); 73 74 Supplier<Stream<Permission>> ss = pc::elementsAsStream; 75 76 Collection<Permission> expected = Collections.list(pc.elements()); 77 withData(TestData.Factory.ofSupplier(description, ss)) 78 .stream(s -> s) 79 .expectedResult(expected) 80 .exercise(); 81 } 82} 83