1 /*
2  * Copyright (C) 2023 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 com.android.tools.metalava.model.testsuite.packageitem
18 
19 import com.android.tools.metalava.model.testsuite.BaseModelTest
20 import com.android.tools.metalava.testing.KnownSourceFiles.nonNullSource
21 import com.android.tools.metalava.testing.html
22 import com.android.tools.metalava.testing.java
23 import kotlin.test.assertEquals
24 import org.junit.Test
25 
26 class CommonPackageItemTest : BaseModelTest() {
27 
28     @Test
Test @hide in package htmlnull29     fun `Test @hide in package html`() {
30         runSourceCodebaseTest(
31             inputSet(
32                 html(
33                     "src/test/pkg/package.html",
34                     """
35                         <HTML>
36                         <BODY>
37                         @hide
38                         </BODY>
39                         </HTML>
40                     """
41                         .trimIndent(),
42                 ),
43                 java(
44                     """
45                         package test.pkg;
46 
47                         public class Foo {}
48                     """
49                         .trimIndent()
50                 ),
51             ),
52         ) {
53             val packageItem = codebase.assertPackage("test.pkg")
54             assertEquals(true, packageItem.originallyHidden)
55         }
56     }
57 
58     @Test
Test @hide in package info processed firstnull59     fun `Test @hide in package info processed first`() {
60         runSourceCodebaseTest(
61             inputSet(
62                 java(
63                     """
64                         /**
65                          * @hide
66                          */
67                         package test.pkg;
68                     """
69                         .trimIndent()
70                 ),
71                 java(
72                     """
73                         package test.pkg;
74 
75                         public class Foo {}
76                     """
77                         .trimIndent()
78                 ),
79             ),
80         ) {
81             val packageItem = codebase.assertPackage("test.pkg")
82             assertEquals(true, packageItem.originallyHidden)
83         }
84     }
85 
86     @Test
Test @hide in package info processed lastnull87     fun `Test @hide in package info processed last`() {
88         runSourceCodebaseTest(
89             inputSet(
90                 java(
91                     """
92                         package test.pkg;
93 
94                         public class Foo {}
95                     """
96                         .trimIndent()
97                 ),
98                 java(
99                     """
100                         /**
101                          * @hide
102                          */
103                         package test.pkg;
104                     """
105                         .trimIndent()
106                 ),
107             ),
108         ) {
109             val packageItem = codebase.assertPackage("test.pkg")
110             assertEquals(true, packageItem.originallyHidden)
111         }
112     }
113 
114     @Test
Test nullability annotation in package infonull115     fun `Test nullability annotation in package info`() {
116         runSourceCodebaseTest(
117             inputSet(
118                 nonNullSource,
119                 java(
120                     """
121                         @android.annotation.NonNull
122                         package test.pkg;
123                     """
124                         .trimIndent()
125                 ),
126                 java(
127                     """
128                         package test.pkg;
129 
130                         public class Foo {}
131                     """
132                         .trimIndent()
133                 ),
134             ),
135         ) {
136             val packageItem = codebase.assertPackage("test.pkg")
137             assertEquals(
138                 "@android.annotation.NonNull",
139                 packageItem.modifiers.annotations().single().toString()
140             )
141         }
142     }
143 }
144