@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"))); } } }
@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(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); } }
/** * JUnit test suite for <em>bean definition profile</em> support in the * Spring TestContext Framework with annotation-based configuration. * * @author Sam Brannen * @since 3.1 */ @RunWith(Suite.class) // Note: the following 'multi-line' layout is for enhanced code readability. @SuiteClasses({// DefaultProfileAnnotationConfigTests.class,// DevProfileAnnotationConfigTests.class,// DevProfileResolverAnnotationConfigTests.class // }) public class ProfileAnnotationConfigTestSuite { }
/** 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(JUnit4.class) public class ObjectKeyTest { @Rule public final KeyTester keyTester = new KeyTester(); @Test public void testEqualsHashCodeAndDigest() throws NoSuchAlgorithmException { Object object = new Object(); keyTester .addEquivalenceGroup(new ObjectKey(object), new ObjectKey(object)) .addEquivalenceGroup(new ObjectKey(new Object())) .addEquivalenceGroup(new ObjectKey("test"), new ObjectKey("test")) .addRegressionTest( new ObjectKey("test"), "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08") .test(); } }
/** * JUnit test suite for <em>bean definition profile</em> support in the * Spring TestContext Framework with XML-based configuration. * * @author Sam Brannen * @since 3.1 */ @RunWith(Suite.class) // Note: the following 'multi-line' layout is for enhanced code readability. @SuiteClasses({// DefaultProfileXmlConfigTests.class,// DevProfileXmlConfigTests.class,// DevProfileResolverXmlConfigTests.class // }) public class ProfileXmlConfigTestSuite { }
@RunWith(Parameterized.class) @Category(AsyncLoggers.class) public class AsyncLoggerThreadContextDefaultTest extends AbstractAsyncThreadContextTestBase { @Parameterized.Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { ContextImpl.WEBAPP, Mode.ALL_ASYNC}, { ContextImpl.WEBAPP, Mode.BOTH_ALL_ASYNC_AND_MIXED}, }); } public AsyncLoggerThreadContextDefaultTest(final ContextImpl contextImpl, final Mode asyncMode) { super(contextImpl, asyncMode); } }
@RunWith(JUnit4.class) public class MediaStoreSignatureTest { @Rule public final KeyTester keyTester = new KeyTester(); @Test public void equalsHashCodeAndDigest() { keyTester .addEquivalenceGroup( new MediaStoreSignature("first", 100, 1), new MediaStoreSignature("first", 100, 1)) .addEquivalenceGroup(new MediaStoreSignature("second", 100, 1)) .addEquivalenceGroup(new MediaStoreSignature("first", 200, 1)) .addEquivalenceGroup(new MediaStoreSignature("first", 100, 2)) .addRegressionTest( new MediaStoreSignature("first", 100, 1), "04959925006b21081000fd10835cc376343c0e922df0bd7346897ede6f958adf") .test(); } }
@RunWith(MockitoJUnitRunner.class) public class DefaultErrorBundleTest { private DefaultErrorBundle defaultErrorBundle; @Mock private Exception mockException; @Before public void setUp() { defaultErrorBundle = new DefaultErrorBundle(mockException); } @Test public void testGetErrorMessageInteraction() { defaultErrorBundle.getErrorMessage(); verify(mockException).getMessage(); } }
/** * Convenience test suite for integration tests that verify support for * {@link WebApplicationContext} {@linkplain ContextLoader context loaders} * in the TestContext framework. * * @author Sam Brannen * @since 3.2 */ @RunWith(Suite.class) // Note: the following 'multi-line' layout is for enhanced code readability. @SuiteClasses({// BasicXmlWacTests.class,// BasicAnnotationConfigWacTests.class,// RequestAndSessionScopedBeansWacTests.class // }) public class WebContextLoaderTestSuite { }
@RunWith(Parameterized.class) @Category(AsyncLoggers.class) public class AsyncLoggerThreadContextCopyOnWriteTest extends AbstractAsyncThreadContextTestBase { @Parameterized.Parameters(name = "{0} {1}") public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { ContextImpl.COPY_ON_WRITE, Mode.ALL_ASYNC}, { ContextImpl.COPY_ON_WRITE, Mode.BOTH_ALL_ASYNC_AND_MIXED} }); } public AsyncLoggerThreadContextCopyOnWriteTest(final ContextImpl contextImpl, final Mode asyncMode) { super(contextImpl, asyncMode); } }
@RunWith(MockitoJUnitRunner.class) public class DiskUserDataStoreTest { private static final int FAKE_USER_ID = 11; private DiskUserDataStore diskUserDataStore; @Mock private UserCache mockUserCache; @Rule public ExpectedException expectedException = ExpectedException.none(); @Before public void setUp() { diskUserDataStore = new DiskUserDataStore(mockUserCache); } @Test public void testGetUserEntityListUnsupported() { expectedException.expect(UnsupportedOperationException.class); diskUserDataStore.userEntityList(); } @Test public void testGetUserEntityDetailesFromCache() { diskUserDataStore.userEntityDetails(FAKE_USER_ID); verify(mockUserCache).get(FAKE_USER_ID); } }
@RunWith(AndroidJUnit4.class) public class ShadowIoUtilsTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Test public void ioUtils() throws Exception { File file = temporaryFolder.newFile("test_file.txt"); Files.asCharSink(file, StandardCharsets.UTF_8).write("some contents"); String contents = IoUtils.readFileAsString(file.getAbsolutePath()); assertThat(contents).isEqualTo("some contents"); } }
@RunWith(RobolectricTestRunner.class) public class AssetRequestHandlerTest { @Mock Context context; @Before public void setUp() { initMocks(this); } @Test public void truncatesFilePrefix() throws IOException { Uri uri = Uri.parse("file:///android_asset/foo/bar.png"); Request request = new Request.Builder(uri).build(); String actual = AssetRequestHandler.getFilePath(request); assertThat(actual).isEqualTo("foo/bar.png"); } }
/** * JUnit 4 based test suite for functionality proposed in <a * href="http://opensource.atlassian.com/projects/spring/browse/SPR-3896" * target="_blank">SPR-3896</a>. * * @author Sam Brannen * @since 2.5 */ @RunWith(Suite.class) // Note: the following 'multi-line' layout is for enhanced code readability. @SuiteClasses({ DefaultLocationsBaseTests.class, DefaultLocationsInheritedTests.class, ExplicitLocationsBaseTests.class, ExplicitLocationsInheritedTests.class, BeanOverridingDefaultLocationsInheritedTests.class, BeanOverridingExplicitLocationsInheritedTests.class }) public class Spr3896SuiteTests { }
@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; } }