Path: blob/master/test/langtools/jdk/jshell/FileManagerTest.java
40931 views
/*1* Copyright (c) 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/*24* @test 817384525* @summary test custom file managers26* @build KullaTesting TestingInputStream27* @run testng FileManagerTest28*/293031import java.io.File;32import java.io.IOException;3334import java.util.Set;35import javax.tools.ForwardingJavaFileManager;36import javax.tools.JavaFileObject;37import javax.tools.JavaFileObject.Kind;38import javax.tools.StandardJavaFileManager;39import org.testng.annotations.BeforeMethod;40import org.testng.annotations.Test;4142import static org.testng.Assert.assertTrue;4344@Test45public class FileManagerTest extends KullaTesting {4647boolean encountered;4849class MyFileManager extends ForwardingJavaFileManager<StandardJavaFileManager>50implements StandardJavaFileManager {5152protected MyFileManager(StandardJavaFileManager fileManager) {53super(fileManager);54}5556@Override57public Iterable<JavaFileObject> list(Location location,58String packageName,59Set<Kind> kinds,60boolean recurse)61throws IOException {62//System.out.printf("list(%s, %s, %s, %b)\n",63// location, packageName, kinds, recurse);64if (packageName.equals("java.lang.reflect")) {65encountered = true;66}67return fileManager.list(location, packageName, kinds, recurse);68}6970@Override71public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {72return fileManager.getJavaFileObjectsFromFiles(files);73}7475@Override76public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {77return fileManager.getJavaFileObjects(files);78}7980@Override81public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {82return fileManager.getJavaFileObjectsFromStrings(names);83}8485@Override86public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {87return fileManager.getJavaFileObjects(names);88}8990@Override91public void setLocation(Location location, Iterable<? extends File> files) throws IOException {92fileManager.setLocation(location, files);93}9495@Override96public Iterable<? extends File> getLocation(Location location) {97return fileManager.getLocation(location);98}99100}101102@BeforeMethod103@Override104public void setUp() {105setUp(b -> b.fileManager(fm -> new MyFileManager(fm)));106}107108public void testSnippetMemberAssignment() {109assertEval("java.lang.reflect.Array.get(new String[1], 0) == null");110assertTrue(encountered, "java.lang.reflect not encountered");111}112113}114115116