View Javadoc

1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package org.apache.commons.classscan.builtin;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  import java.net.URISyntaxException;
19  import java.util.Map;
20  
21  import org.apache.commons.classscan.ClassPath;
22  import org.apache.commons.classscan.ClassPathElement;
23  import org.apache.commons.classscan.MetaRegistry;
24  import org.apache.commons.classscan.ResourceFile;
25  import org.apache.commons.classscan.test.classes.FullInterface;
26  import org.junit.Before;
27  import org.junit.Test;
28  
29  public class UrlClassPathTest {
30  
31      ClassPath classPath;
32  
33      @Before
34      public void loadLocation() throws URISyntaxException {
35      	ClassLoader classLoader = getClass().getClassLoader();
36  		classPath = MetaRegistry.DEFAULT_REGISTRY.getClassPath(classLoader);
37      }
38  
39      @Test
40      public void testGetClassLocationsWithMetaFile() throws URISyntaxException {
41      	String serviceFileName = "META-INF/services/"+FullInterface.class.getCanonicalName();
42  
43      	Map<ClassPathElement, ResourceFile> resources = classPath.getResources(serviceFileName);
44      	assertEquals(1, resources.size());
45      	
46      	for(Map.Entry<ClassPathElement, ResourceFile> entry : resources.entrySet()) {
47      		ResourceFile file = entry.getValue();
48      		assertEquals(serviceFileName, file.getFileName());
49      	}
50      }
51  }