1 package junitx.util; 2 3 import junit.framework.TestCase; 4 import junitx.framework.Assert; 5 6 10 public class MockedSuiteBuilderTest extends TestCase { 11 12 public MockedSuiteBuilderTest(String name) { 13 super(name); 14 } 15 16 public void testIsGifTestClass() { 17 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 18 19 Assert.assertFalse(builder.isTestClass("logo.gif")); 20 Assert.assertFalse(builder.isTestClass("junit/awtui/logo.gif")); 21 } 22 23 public void testIsSubclassTestClass() { 24 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 25 26 Assert.assertFalse(builder.isTestClass("TestRunner$1.class")); 27 Assert.assertFalse(builder.isTestClass("junit/awtui/TestRunner$1.class")); 28 } 29 30 public void testIsTestClass() { 31 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 32 33 assertTrue(builder.isTestClass("SuiteTest.class")); 34 assertTrue(builder.isTestClass("junit/tests/framework/SuiteTest.class")); 35 } 36 37 public void testIsTestClassPrefix() { 38 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 39 TestFilter filter = new SimpleTestFilter() { 40 public boolean include(String classpath) { 41 return getClassName(classpath).startsWith("Test"); 42 } 43 }; 44 builder.setFilter(filter); 45 46 assertTrue(builder.isTestClass("TestSuite.class")); 47 assertTrue(builder.isTestClass("junit/tests/framework/TestSuite.class")); 48 49 Assert.assertFalse(builder.isTestClass("TestRunner$1.class")); 50 Assert.assertFalse(builder.isTestClass("junit/awtui/TestRunner$1.class")); 51 } 52 53 public void testIsTestClassNullPrefix() { 54 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 55 56 assertTrue(builder.isTestClass("SuiteTest.class")); 57 assertTrue(builder.isTestClass("junit/tests/framework/SuiteTest.class")); 58 59 Assert.assertFalse(builder.isTestClass("TestRunner$1.class")); 60 Assert.assertFalse(builder.isTestClass("junit/awtui/TestRunner$1.class")); 61 } 62 63 public void testIsTestClassSuffix() { 64 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 65 TestFilter filter = new SimpleTestFilter() { 66 public boolean include(String classpath) { 67 return getClassName(classpath).endsWith("Tests"); 68 } 69 }; 70 builder.setFilter(filter); 71 72 assertTrue(builder.isTestClass("AllTests.class")); 73 assertTrue(builder.isTestClass("junit/tests/framework/AllTests.class")); 74 75 Assert.assertFalse(builder.isTestClass("AllTests$1.class")); 76 Assert.assertFalse(builder.isTestClass("junit/awtui/AllTests$1.class")); 77 } 78 79 public void testIsTestClassNullSuffix() { 80 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 81 82 assertTrue(builder.isTestClass("SuiteTest.class")); 83 assertTrue(builder.isTestClass("junit/tests/framework/SuiteTest.class")); 84 85 Assert.assertFalse(builder.isTestClass("TestRunner$1.class")); 86 Assert.assertFalse(builder.isTestClass("junit/awtui/TestRunner$1.class")); 87 } 88 89 public void testIsTestClassPackage() { 90 MockedSuiteBuilder builder = new MockedSuiteBuilder(); 91 TestFilter filter = new SimpleTestFilter() { 92 public boolean include(String classpath) { 93 return getPackageName(classpath).startsWith("junit.tests.framework"); 94 } 95 }; 96 builder.setFilter(filter); 97 98 Assert.assertFalse(builder.isTestClass("SuiteTest.class")); 99 Assert.assertFalse(builder.isTestClass("junit/tests/SuiteTest.class")); 100 assertTrue(builder.isTestClass("junit/tests/framework/SuiteTest.class")); 101 102 Assert.assertFalse(builder.isTestClass("SuiteTest$1.class")); 103 Assert.assertFalse(builder.isTestClass("junit/tests/framework/SuiteTest$1.class")); 104 } 105 106 private static class MockedSuiteBuilder extends AbstractSuiteBuilder { 107 private MockedSuiteBuilder() { 108 super(null); 109 } 110 } 111 112 } | Popular Tags |