Path: blob/master/test/jdk/java/security/PermissionCollection/PermissionCollectionStreamTest.java
41149 views
/*1* Copyright (c) 2015, 2017, 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/* @test24* @bug 808167825* @summary Tests for stream returning methods26* @library /lib/testlibrary/bootlib27* @build java.base/java.util.stream.OpTestCase28* @run testng/othervm PermissionCollectionStreamTest29*/3031import org.testng.annotations.DataProvider;32import org.testng.annotations.Test;3334import java.io.FilePermission;35import java.security.Permission;36import java.security.PermissionCollection;37import java.util.Collection;38import java.util.Collections;39import java.util.function.Supplier;40import java.util.stream.OpTestCase;41import java.util.stream.Stream;42import java.util.stream.TestData;4344public class PermissionCollectionStreamTest extends OpTestCase {4546@DataProvider47public static Object[][] permissions() {48return new Object[][]{49{50"FilePermission",51new Permission[]{52new FilePermission("/tmp/foobar", "read"),53new FilePermission("/tmp/foo", "write"),54new FilePermission("/tmp/foobar", "read,write"),55}56},57};58}596061private PermissionCollection create(Permission[] pa) {62PermissionCollection pc = pa[0].newPermissionCollection();63for (Permission p : pa) {64pc.add(p);65}66return pc;67}6869@Test(dataProvider = "permissions")70public void testElementsAsStream(String description, Permission[] pa) {71PermissionCollection pc = create(pa);7273Supplier<Stream<Permission>> ss = pc::elementsAsStream;7475Collection<Permission> expected = Collections.list(pc.elements());76withData(TestData.Factory.ofSupplier(description, ss))77.stream(s -> s)78.expectedResult(expected)79.exercise();80}81}828384