@Override public Runner runnerForClass(Class<?> testClass) throws Exception { RunWith annotation = testClass.getAnnotation(RunWith.class); if (annotation != null) { return buildRunner(annotation.value(), testClass); } return null; }
@RunWith(Parameterized.class) @Category({ ReplicationTests.class, LargeTests.class }) public class TestReplicationSmallTestsSync extends TestReplicationSmallTests { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestReplicationSmallTestsSync.class); @Override protected boolean isSyncPeer() { return true; } }
@RunWith(SpringRunner.class) public static abstract class BaseTestCase { @Test public void testNothing() { } }
@RunWith(JUnit4.class) public class EmptySignatureTest { @Rule public final KeyTester keyTester = new KeyTester(); @Test public void testEquals() { keyTester .addEquivalenceGroup( EmptySignature.obtain(), EmptySignature.obtain()) .addEquivalenceGroup(mock(Key.class)) .addEmptyDigestRegressionTest(EmptySignature.obtain()) .test(); } }
@RunWith(MockitoJUnitRunner.class) public class StartDeploymentTest { private static final String ENVIRONMENT_NAME = "TestEnvironment"; private static final String ENVIRONMENT_REVISION_ID = "1"; @Mock private HttpServletRequest request; @Mock private DataService dataService; @Mock private StartDeploymentMapper mapper; @Mock private ApiGatewayRequestContext context; @InjectMocks private StartDeployment api;
@RunWith(MockitoJUnitRunner.class) public static class TestUnit { @Mock HttpResponse proxyResp; @Mock HttpRequestMessage request; @Test public void testIsValidResponseHeader() { Assert.assertTrue(isValidResponseHeader(HttpHeaderNames.get("test"))); Assert.assertFalse(isValidResponseHeader(HttpHeaderNames.get("Keep-Alive"))); Assert.assertFalse(isValidResponseHeader(HttpHeaderNames.get("keep-alive"))); } } }
@Category(RequiresOpenshift.class) @RequiresOpenshift @RunWith(ArquillianConditionalRunner.class) public class HelloPodDeploymentOpenShiftITCase { @ArquillianResource private URL base; @Deployment(testable = false) public static WebArchive deploy() { return ShrinkWrap.create(WebArchive.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @Test public void shouldBeAbleToInjectURL() throws Exception { Assert.assertNotNull(base); } }
/** Integration tests for database admin functionality: DDL etc. */ @Category(IntegrationTest.class) @RunWith(JUnit4.class) public class ITDatabaseTest { @ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(); @Rule public ExpectedException expectedException = ExpectedException.none(); @Test public void badDdl() { expectedException.expect(isSpannerException(ErrorCode.INVALID_ARGUMENT)); expectedException.expectMessage("Syntax error on line 1"); env.getTestHelper().createTestDatabase("CREATE TABLE T ( Illegal Way To Define A Table )"); } }
@RunWith(RobolectricTestRunner.class) public class MockitoInjectMocksTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock TextView textView; @InjectMocks Activity activity = Robolectric.setupActivity(Activity.class); @Test public void testInjection() { activity.finish(); } }
@RunWith(Parameterized.class) @Category(AsyncLoggers.class) public class AsyncLoggerThreadContextGarbageFreeTest extends AbstractAsyncThreadContextTestBase { @Parameterized.Parameters(name = "{0} {1}") public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { ContextImpl.GARBAGE_FREE, Mode.ALL_ASYNC}, { ContextImpl.GARBAGE_FREE, Mode.BOTH_ALL_ASYNC_AND_MIXED}, }); } public AsyncLoggerThreadContextGarbageFreeTest(final ContextImpl contextImpl, final Mode asyncMode) { super(contextImpl, asyncMode); } }
/** * Test case for Compression.Algorithm.NONE and no use data block encoding. * @see org.apache.hadoop.hbase.regionserver.TestMultiColumnScanner */ @RunWith(Parameterized.class) @Category({ RegionServerTests.class, LargeTests.class }) public class TestMultiColumnScannerWithNoneAndUseDataEncoding extends TestMultiColumnScanner { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestMultiColumnScannerWithNoneAndUseDataEncoding.class); @Parameters public static Collection<Object[]> parameters() { return TestMultiColumnScanner.generateParams(Algorithm.NONE, true); } }
/** * @author Sam Brannen * @since 4.3 */ @RunWith(SpringRunner.class) public class BootstrapWithInterfaceTests implements BootstrapWithTestInterface { @Autowired String foo; @Test public void injectedBean() { assertEquals("foo", foo); } }
/** * This class is an extension of {@link EnabledAndIgnoredSpringRunnerTests} * that has been modified to use {@link SpringClassRule} and * {@link SpringMethodRule}. * * @author Sam Brannen * @since 4.2 */ @RunWith(JUnit4.class) public class EnabledAndIgnoredSpringRuleTests extends EnabledAndIgnoredSpringRunnerTests { @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); // All tests are in superclass. }
/** * Verifies support for JUnit 4.7 {@link Rule Rules} in conjunction with the * {@link SpringRunner}. The body of this test class is taken from the * JUnit 4.7 release notes. * * @author JUnit 4.7 Team * @author Sam Brannen * @since 3.0 */ @RunWith(SpringRunner.class) @TestExecutionListeners( {}) public class SpringJUnit47ClassRunnerRuleTests { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals("testA", name.getMethodName()); } @Test public void testB() { assertEquals("testB", name.getMethodName()); } }
@RunWith(MockitoJUnitRunner.StrictStubs.class) public class ListEnvironmentsTest { private static final String CLUSTER = "cluster"; private static final String ENVIRONMENT_NAME_PREFIX = "environmentNamePrefix"; @Mock private HttpServletRequest request; @Mock private DataService dataService; @Mock private ListEnvironmentsMapper mapper; @Mock private ApiGatewayRequestContext context; @Mock private ListEnvironmentsRequest dsRequest; @Mock private RequestPagination pagination; @InjectMocks private ListEnvironments api;