1 /*
2  * Copyright (C) 2017 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.compatibility.common.tradefed.result;
18 
19 
20 import com.android.compatibility.common.util.IInvocationResult;
21 import com.android.compatibility.common.util.InvocationResult;
22 import junit.framework.TestCase;
23 import java.util.HashMap;
24 import java.util.Map;
25 
26 /**
27  * Unit tests for {@link ResultReporter}, focused on ability to override build info.
28  */
29 public class ResultReporterBuildInfoTest extends TestCase {
30 
testOverrideBuildProperties()31     public void testOverrideBuildProperties() {
32         ResultReporterBuildInfoTester tester = new ResultReporterBuildInfoTester();
33         String manufacture = "custom_manufacture";
34         String brand = "google";
35         String product = "gProduct";
36         String device = "gDevice";
37         String version = "gVersion";
38         String buildId = "123";
39         String model = "gModel";
40         String fingerprint = brand + "/" + product + "/" + device + ":" +
41                 version + "/" + buildId + "/userdebug-keys";
42 
43         IInvocationResult result = tester.testBuildInfoOverride(fingerprint, manufacture, model);
44         Map<String, String> invocationInfo = result.getInvocationInfo();
45         assertEquals(invocationInfo.get(ResultReporter.BUILD_ID), buildId);
46         assertEquals(invocationInfo.get(ResultReporter.BUILD_BRAND), brand);
47         assertEquals(invocationInfo.get(ResultReporter.BUILD_DEVICE), device);
48         assertEquals(invocationInfo.get(ResultReporter.BUILD_PRODUCT), product);
49         assertEquals(invocationInfo.get(ResultReporter.BUILD_VERSION_RELEASE), version);
50         assertEquals(invocationInfo.get(ResultReporter.BUILD_FINGERPRINT), fingerprint);
51         assertEquals(invocationInfo.get(ResultReporter.BUILD_MANUFACTURER), manufacture);
52         assertEquals(invocationInfo.get(ResultReporter.BUILD_MODEL), model);
53     }
54 
55     public static class ResultReporterBuildInfoTester extends ResultReporter {
56 
ResultReporterBuildInfoTester()57         public ResultReporterBuildInfoTester() {
58             mResult = new InvocationResult();
59         }
60 
testBuildInfoOverride(String buildFingerprintOverride, String manufactureOverride, String modelOverride)61         public IInvocationResult testBuildInfoOverride(String buildFingerprintOverride,
62                 String manufactureOverride, String modelOverride) {
63             addDeviceBuildInfoToResult(
64                     buildFingerprintOverride, manufactureOverride, modelOverride);
65             return mResult;
66         }
67 
68         @Override
mapBuildInfo()69         protected Map<String, String> mapBuildInfo() {
70             Map<String, String> buildProperties = new HashMap<>();
71             buildProperties.put(BUILD_ID, BUILD_ID);
72             buildProperties.put(BUILD_BRAND, BUILD_BRAND);
73             buildProperties.put(BUILD_DEVICE, BUILD_DEVICE);
74             buildProperties.put(BUILD_PRODUCT, BUILD_PRODUCT);
75             buildProperties.put(BUILD_VERSION_RELEASE, BUILD_VERSION_RELEASE);
76             buildProperties.put(BUILD_FINGERPRINT, BUILD_FINGERPRINT);
77             buildProperties.put(BUILD_MANUFACTURER, BUILD_MANUFACTURER);
78             buildProperties.put(BUILD_MODEL, BUILD_MODEL);
79             return buildProperties;
80         }
81     }
82 }
83