+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2007 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// FileResourceTest.java\r
-// Since: Jul 5, 2007 11:05:34 AM\r
-//\r
-// $URL:http://www.xerial.org/svn/project/XerialJ/trunk/XerialJ/src/test/java/org/xerial/util/FileResourceTest.java $\r
-// $Author:leo $\r
-//--------------------------------------\r
-package org.xerial.util;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.net.URISyntaxException;\r
-import java.net.URL;\r
-import java.util.List;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.xerial.util.io.VirtualFile;\r
-import org.xerial.util.log.Logger;\r
-\r
-public class FileResourceTest\r
-{\r
- private Logger _logger = Logger.getLogger(FileResourceTest.class);\r
- \r
- \r
- @Before\r
- public void setUp() throws Exception\r
- {\r
- }\r
-\r
- @After\r
- public void tearDown() throws Exception\r
- {}\r
-\r
- @Test\r
- public void find() throws IOException\r
- {\r
- URL loc = FileResource.find(FileResourceTest.class, "test-resource.txt");\r
- _logger.trace("resource URL: " + loc);\r
- assertNotNull(loc);\r
- BufferedReader in = new BufferedReader(new InputStreamReader(loc.openStream()));\r
- String line = in.readLine();\r
- assertNotNull(line);\r
- assertEquals("hello world", line);\r
- }\r
- \r
- \r
- @Test\r
- public void findFromRootPackage() throws URISyntaxException\r
- {\r
- URL url = FileResource.find("empty.file");\r
- assertNotNull(url);\r
- File file = new File(url.toURI());\r
- assertEquals("empty.file", file.getName());\r
- }\r
-\r
- @Test\r
- public void listResources()\r
- {\r
- List<VirtualFile> resourceList = FileResource.listResources("org.xerial.util");\r
- \r
- for(VirtualFile vf : resourceList)\r
- {\r
- _logger.trace(vf.getLogicalPath() + " : " + vf.getURL());\r
- }\r
- \r
- }\r
- \r
- @Test \r
- public void filter()\r
- {\r
- List<VirtualFile> resourceList = FileResource.listResources("org.xerial.util", new ResourceFilter(){\r
- public boolean accept(String resourcePath)\r
- {\r
- return resourcePath.endsWith(".java");\r
- }\r
- });\r
- \r
- for(VirtualFile vf : resourceList)\r
- {\r
- assertTrue(vf.getLogicalPath().endsWith(".java"));\r
- }\r
- }\r
- \r
- @Test\r
- public void listResoucesInJAR()\r
- {\r
- List<VirtualFile> resourceList = FileResource.listResources("org.junit.runner");\r
- assertTrue("at least one resource must be found in org.junit.runner", resourceList.size() > 0);\r
- \r
- for(VirtualFile vf : resourceList)\r
- {\r
- _logger.trace(vf.getLogicalPath() + " : " + vf.getURL());\r
- }\r
- }\r
-\r
-}\r