• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package signature.converter;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import java.io.IOException;
22 
23 import org.junit.Test;
24 
25 import signature.converter.util.AbstractConvertTest;
26 import signature.converter.util.CompilationUnit;
27 import signature.model.IAnnotation;
28 import signature.model.IApi;
29 import signature.model.IPackage;
30 import signature.model.util.ModelUtil;
31 
32 public abstract class ConvertPackageTest extends AbstractConvertTest {
33 
34     // tests whether package annotations are returned
35     @Test
testPackageAnnotation()36     public void testPackageAnnotation() throws IOException {
37         CompilationUnit packageSrc = new CompilationUnit("a.package-info", "@Deprecated package a;");
38         CompilationUnit classSrc = new CompilationUnit("a.X", "package a; public class X{}");
39         IApi api = convert(classSrc, packageSrc);
40         IPackage sigPackage = ModelUtil.getPackage(api, "a");
41         assertEquals(1, sigPackage.getAnnotations().size());
42         IAnnotation annotation = sigPackage.getAnnotations().iterator().next();
43         assertEquals("java.lang.Deprecated", annotation.getType().getClassDefinition().getQualifiedName());
44     }
45 
46     // tests that package-info is not returned as class
47     @Test
testNumberOfClasses1()48     public void testNumberOfClasses1() throws IOException {
49         CompilationUnit packageSrc = new CompilationUnit("a.package-info", "@Deprecated package a;");
50         CompilationUnit classSrc = new CompilationUnit("a.X", "package a; public class X{}");
51         IApi api = convert(classSrc, packageSrc);
52         IPackage sigPackage = ModelUtil.getPackage(api, "a");
53         assertEquals(1, sigPackage.getClasses().size());
54     }
55 
56     // tests that nested classes are returned as package classes
57     @Test
testNumberOfClasses2()58     public void testNumberOfClasses2() throws IOException {
59         CompilationUnit src = new CompilationUnit("a.X",
60                 "package a;" +
61                 "public class X{" +
62                 "   public static class Y{}" +
63                 "}");
64         IApi api = convert(src);
65         IPackage sigPackage = ModelUtil.getPackage(api, "a");
66         assertEquals(2, sigPackage.getClasses().size());
67     }
68 
69 }