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