1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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
17package com.android.ide.eclipse.adt.internal.launch.junit.runtime;
18
19import org.eclipse.jdt.internal.junit.runner.ITestIdentifier;
20import org.eclipse.jdt.internal.junit.runner.ITestReference;
21import org.eclipse.jdt.internal.junit.runner.TestExecution;
22
23/**
24 * Base implementation of the Eclipse {@link ITestReference} and {@link ITestIdentifier} interfaces
25 * for Android tests.
26 * <p/>
27 * Provides generic equality/hashcode services
28 */
29@SuppressWarnings("restriction")
30abstract class AndroidTestReference implements ITestReference, ITestIdentifier {
31
32    /**
33     * Gets the {@link ITestIdentifier} for this test reference.
34     */
35    @Override
36    public ITestIdentifier getIdentifier() {
37        // this class serves as its own test identifier
38        return this;
39    }
40
41    /**
42     * Not supported.
43     */
44    @Override
45    public void run(TestExecution execution) {
46        throw new UnsupportedOperationException();
47    }
48
49    /**
50     * Compares {@link ITestIdentifier} using names
51     */
52    @Override
53    public boolean equals(Object obj) {
54        if (obj instanceof ITestIdentifier) {
55            ITestIdentifier testid = (ITestIdentifier) obj;
56            return getName().equals(testid.getName());
57        }
58        return false;
59    }
60
61    @Override
62    public int hashCode() {
63        return getName().hashCode();
64    }
65}
66