Home | History | Annotate | Download | only in junit
      1 /*
      2  * Copyright (C) 2015 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 vogar.target.junit;
     18 
     19 import java.util.List;
     20 
     21 import org.junit.Before;
     22 import org.junit.Test;
     23 import org.junit.runner.RunWith;
     24 import org.junit.runners.JUnit4;
     25 import vogar.target.junit3.SimpleTest;
     26 import vogar.target.junit3.SimpleTest2;
     27 import vogar.target.junit3.SuiteTest;
     28 import vogar.target.junit3.WrongSuiteTest;
     29 
     30 import static junit.framework.Assert.assertEquals;
     31 
     32 /**
     33  * Tests for {@link JUnitRunnerFactory}
     34  */
     35 @RunWith(JUnit4.class)
     36 public class JUnitRunnerFactoryTest {
     37     private JUnitRunnerFactory runnerFactory;
     38 
     39     @Before
     40     public void setUp() throws Exception {
     41         runnerFactory = new JUnitRunnerFactory();
     42     }
     43 
     44     @Test
     45     public void test_supports_should_judge_whether_Object_is_not_supported() {
     46         assertEquals(false, runnerFactory.supports(Object.class));
     47     }
     48 
     49     @Test
     50     public void test_supports_should_judge_whether_SimpleTest_which_inherits_from_TestCase_is_supported() {
     51         assertEquals(true, runnerFactory.supports(SimpleTest.class));
     52     }
     53 
     54     @Test
     55     public void test_supports_should_judge_whether_WrongSuiteTest_which_has_suite_non_static_method_is_not_supported() {
     56         assertEquals(false, runnerFactory.supports(WrongSuiteTest.class));
     57     }
     58 
     59     @Test
     60     public void test_supports_should_judge_whether_SuiteTest_which_has_suite_static_method_is_supported() {
     61         assertEquals(true, runnerFactory.supports(SuiteTest.class));
     62     }
     63 
     64     @Test
     65     public void test_method_names_merged() {
     66         List<VogarTest> tests = JUnitRunnerFactory.createVogarTests(SimpleTest2.class, "testSimple2",
     67                 new String[]{"testSimple2", "testSimple1"});
     68 
     69         assertEquals("[vogar.target.junit3.SimpleTest2#testSimple2,"
     70                         + " vogar.target.junit3.SimpleTest2#testSimple1]",
     71                 tests.toString());
     72     }
     73 }
     74