1 /* 2 * Copyright (C) 2008 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.ddmlib.testrunner; 18 19 /** 20 * Identifies a parsed instrumentation test. 21 */ 22 public class TestIdentifier { 23 24 private final String mClassName; 25 private final String mTestName; 26 27 /** 28 * Creates a test identifier. 29 * 30 * @param className fully qualified class name of the test. Cannot be null. 31 * @param testName name of the test. Cannot be null. 32 */ 33 public TestIdentifier(String className, String testName) { 34 if (className == null || testName == null) { 35 throw new IllegalArgumentException("className and testName must " + 36 "be non-null"); 37 } 38 mClassName = className; 39 mTestName = testName; 40 } 41 42 /** 43 * Returns the fully qualified class name of the test. 44 */ 45 public String getClassName() { 46 return mClassName; 47 } 48 49 /** 50 * Returns the name of the test. 51 */ 52 public String getTestName() { 53 return mTestName; 54 } 55 56 /** 57 * Tests equality by comparing class and method name. 58 */ 59 @Override 60 public boolean equals(Object other) { 61 if (!(other instanceof TestIdentifier)) { 62 return false; 63 } 64 TestIdentifier otherTest = (TestIdentifier)other; 65 return getClassName().equals(otherTest.getClassName()) && 66 getTestName().equals(otherTest.getTestName()); 67 } 68 69 /** 70 * Generates hashCode based on class and method name. 71 */ 72 @Override 73 public int hashCode() { 74 return getClassName().hashCode() * 31 + getTestName().hashCode(); 75 } 76 77 /** 78 * Generates user friendly string. 79 */ 80 @Override 81 public String toString() { 82 return String.format("%s#%s", getClassName(), getTestName()); 83 } 84 } 85