Home | History | Annotate | Download | only in runtime
      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 
     17 package com.android.ide.eclipse.adt.internal.launch.junit.runtime;
     18 
     19 import com.android.ddmlib.testrunner.TestIdentifier;
     20 
     21 import org.eclipse.jdt.internal.junit.runner.IVisitsTestTrees;
     22 
     23 /**
     24  * Reference for a single Android test method.
     25  */
     26 @SuppressWarnings("restriction")
     27 class TestCaseReference extends AndroidTestReference {
     28     private final String mClassName;
     29     private final String mTestName;
     30     private final String mDeviceName;
     31 
     32     /**
     33      * Creates a TestCaseReference from a {@link TestIdentifier}
     34      * @param test
     35      */
     36     TestCaseReference(String deviceName, TestIdentifier test) {
     37         mDeviceName = deviceName;
     38         mClassName = test.getClassName();
     39         mTestName = test.getTestName();
     40     }
     41 
     42     /**
     43      * Returns a count of the number of test cases referenced. Is always one for this class.
     44      */
     45     @Override
     46     public int countTestCases() {
     47         return 1;
     48     }
     49 
     50     /**
     51      * Sends test identifier and test count information for this test
     52      *
     53      * @param notified the {@link IVisitsTestTrees} to send test info to
     54      */
     55     @Override
     56     public void sendTree(IVisitsTestTrees notified) {
     57         notified.visitTreeEntry(getIdentifier(), false, countTestCases());
     58     }
     59 
     60     /**
     61      * Returns the identifier of this test, in a format expected by JDT JUnit
     62      */
     63     @Override
     64     public String getName() {
     65         return String.format("%s (%s) [%s]", mTestName, mClassName, mDeviceName);
     66     }
     67 }
     68