1 /*
2  * Copyright (C) 2016 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.cts.apicoverage;
18 
19 import java.lang.String;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.concurrent.ConcurrentHashMap;
28 
29 /** Representation of the entire CDD. */
30 class CddCoverage {
31 
32     private final Map<String, CddRequirement> requirements = new ConcurrentHashMap<>();
33 
addCddRequirement(CddRequirement cddRequirement)34     public void addCddRequirement(CddRequirement cddRequirement) {
35         requirements.put(cddRequirement.getRequirementId(), cddRequirement);
36     }
37 
getCddRequirements()38     public Collection<CddRequirement> getCddRequirements() {
39         return Collections.unmodifiableCollection(requirements.values());
40     }
41 
addCoverage(String cddRequirementId, TestMethod testMethod)42     public void addCoverage(String cddRequirementId, TestMethod testMethod) {
43         if (cddRequirementId == null)
44             return;
45 
46         requirements.putIfAbsent(cddRequirementId, new CddRequirement(cddRequirementId));
47         requirements.get(cddRequirementId).addTestMethod(testMethod);
48     }
49 
50     static class CddRequirement {
51         private final String mRequirementId;
52         private final List<TestMethod> mtestMethods;
53 
CddRequirement(String requirementId)54         CddRequirement(String requirementId) {
55             this.mRequirementId = requirementId;
56             this.mtestMethods = Collections.synchronizedList(new ArrayList<>());
57         }
58 
59         @Override
equals(Object other)60         public boolean equals(Object other) {
61             if (other == null) {
62                 return false;
63             } else if (!(other instanceof CddRequirement)) {
64                 return false;
65             } else {
66                 return mRequirementId.equals(((CddRequirement)other).mRequirementId);
67             }
68         }
69 
70         @Override
hashCode()71         public int hashCode() {
72             return mRequirementId.hashCode();
73         }
74 
75         @Override
toString()76         public String toString() {
77             return String.format("Requirement %s %s", mRequirementId, mtestMethods);
78         }
79 
getRequirementId()80         public String getRequirementId() { return mRequirementId; }
81 
addTestMethod(TestMethod testMethod)82         public void addTestMethod(TestMethod testMethod) {
83             mtestMethods.add(testMethod);
84         }
85 
getTestMethods()86         public Collection<TestMethod> getTestMethods() {
87             return Collections.unmodifiableCollection(mtestMethods);
88         }
89     }
90 
91     static class TestMethod {
92         private final String mTestModule;
93         private final String mTestClass;
94         private final String mTestMethod;
95 
TestMethod(String testModule, String testClass, String testMethod)96         TestMethod(String testModule, String testClass, String testMethod) {
97             this.mTestModule = testModule;
98             this.mTestClass = testClass;
99             this.mTestMethod = testMethod;
100         }
101 
getTestModule()102         public String getTestModule() { return mTestModule; }
103 
getTestClass()104         public String getTestClass() { return mTestClass; }
105 
getTestMethod()106         public String getTestMethod() { return mTestMethod; }
107 
108         @Override
toString()109         public String toString() {
110             return String.format("%s %s#%s", mTestModule, mTestClass, mTestMethod);
111         }
112     }
113 }
114