• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.server.art.model;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import androidx.test.filters.SmallTest;
22 import androidx.test.runner.AndroidJUnit4;
23 
24 import com.android.server.art.proto.BatchDexoptParamsProto;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 import java.lang.reflect.Method;
30 import java.lang.reflect.Modifier;
31 import java.util.Arrays;
32 import java.util.List;
33 import java.util.stream.Collectors;
34 
35 @SmallTest
36 @RunWith(AndroidJUnit4.class)
37 public class BatchDexoptParamsTest {
38     @Test
testToProto()39     public void testToProto() {
40         // Update this test with new fields if this assertion fails.
41         checkFieldCoverage();
42 
43         BatchDexoptParams params = new BatchDexoptParams
44                                            .Builder(List.of("package_a", "package_b"),
45                                                    new DexoptParams.Builder("install").build())
46                                            .build();
47 
48         BatchDexoptParamsProto proto = params.toProto();
49 
50         assertThat(proto.getPackageList())
51                 .containsExactlyElementsIn(params.getPackages())
52                 .inOrder();
53         assertThat(proto.getDexoptParams().getReason())
54                 .isEqualTo(params.getDexoptParams().getReason());
55     }
56 
57     @Test
testFromProto()58     public void testFromProto() {
59         // Update this test with new fields if this assertion fails.
60         checkFieldCoverage();
61 
62         BatchDexoptParamsProto proto =
63                 BatchDexoptParamsProto.newBuilder()
64                         .addAllPackage(List.of("package_a", "package_b"))
65                         .setDexoptParams(new DexoptParams.Builder("install").build().toProto())
66                         .build();
67 
68         BatchDexoptParams params = BatchDexoptParams.fromProto(proto);
69 
70         assertThat(params.getPackages())
71                 .containsExactlyElementsIn(proto.getPackageList())
72                 .inOrder();
73         assertThat(params.getDexoptParams().getReason())
74                 .isEqualTo(proto.getDexoptParams().getReason());
75     }
76 
checkFieldCoverage()77     private void checkFieldCoverage() {
78         assertThat(Arrays.stream(BatchDexoptParams.class.getDeclaredMethods())
79                            .filter(method -> Modifier.isAbstract(method.getModifiers()))
80                            .map(Method::getName)
81                            .collect(Collectors.toList()))
82                 .containsExactly("getPackages", "getDexoptParams");
83     }
84 }
85