1 /* 2 * Copyright (C) 2011 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 package com.android.cts.xmlgenerator; 17 18 import java.util.ArrayList; 19 import java.util.Collection; 20 import java.util.Collections; 21 import java.util.HashMap; 22 import java.util.List; 23 import java.util.Map; 24 25 class TestSuite implements Comparable<TestSuite> { 26 27 private final String mName; 28 29 private final Map<String, TestSuite> mSuites = new HashMap<String, TestSuite>(); 30 31 private final List<TestCase> mCases = new ArrayList<TestCase>(); 32 TestSuite(String name)33 public TestSuite(String name) { 34 mName = name; 35 } 36 getName()37 public String getName() { 38 return mName; 39 } 40 hasSuite(String name)41 public boolean hasSuite(String name) { 42 return mSuites.containsKey(name); 43 } 44 getSuite(String name)45 public TestSuite getSuite(String name) { 46 return mSuites.get(name); 47 } 48 addSuite(TestSuite suite)49 public void addSuite(TestSuite suite) { 50 mSuites.put(suite.mName, suite); 51 } 52 getSuites()53 public Collection<TestSuite> getSuites() { 54 return Collections.unmodifiableCollection(mSuites.values()); 55 } 56 addCase(TestCase testCase)57 public void addCase(TestCase testCase) { 58 mCases.add(testCase); 59 } 60 getCases()61 public Collection<TestCase> getCases() { 62 return Collections.unmodifiableCollection(mCases); 63 } 64 65 @Override compareTo(TestSuite another)66 public int compareTo(TestSuite another) { 67 return getName().compareTo(another.getName()); 68 } 69 countTests()70 public int countTests() { 71 int count = 0; 72 for (TestSuite suite : mSuites.values()) { 73 count += suite.countTests(); 74 } 75 for (TestCase testCase : mCases) { 76 count += testCase.countTests(); 77 } 78 return count; 79 } 80 } 81