Search in sources :

Example 1 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project glide by bumptech.

the class CachingTest method submit_withRequestLoadingWithOnlyRetrieveFromCache_andNotInCache_doesNotFail.

// Tests #2428.
@Test
public void submit_withRequestLoadingWithOnlyRetrieveFromCache_andNotInCache_doesNotFail() {
    // Block the main thread so that we know that both requests will be queued but not started at
    // the same time.
    final CountDownLatch blockMainThread = new CountDownLatch(1);
    new Handler(Looper.getMainLooper()).post(new Runnable() {

        @Override
        public void run() {
            try {
                blockMainThread.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    // Queue the retrieve from cache request first.
    final Future<Drawable> firstQueuedFuture = GlideApp.with(context).load(ResourceIds.raw.canonical).onlyRetrieveFromCache(true).submit();
    // Then queue the normal request.
    FutureTarget<Drawable> expectedFuture = GlideApp.with(context).load(ResourceIds.raw.canonical).submit();
    // Run the requests.
    blockMainThread.countDown();
    // Verify that the request that didn't have retrieve from cache succeeds
    assertThat(concurrency.get(expectedFuture)).isNotNull();
    // The first request only from cache should fail because the item is not in cache.
    assertThrows(RuntimeException.class, new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            concurrency.get(firstQueuedFuture);
        }
    });
}
Also used : ThrowingRunnable(org.junit.function.ThrowingRunnable) Drawable(android.graphics.drawable.Drawable) Matchers.anyDrawable(com.bumptech.glide.test.Matchers.anyDrawable) Handler(android.os.Handler) CountDownLatch(java.util.concurrent.CountDownLatch) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 2 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project hippo by NHS-digital-website.

the class CommonmarkMarkdownConverterTest method throwsException_onNegativeTopHeadingLevel.

@Test
public void throwsException_onNegativeTopHeadingLevel() {
    // given
    final String irrelevantMarkdown = randomString();
    final String irrelevantHeadingIdPrefix = randomString();
    final int illegalTopLevelHeading = -RandomUtils.nextInt();
    // when
    final ThrowingRunnable action = () -> commonmarkMarkdownConverter.toHtml(irrelevantMarkdown, irrelevantHeadingIdPrefix, illegalTopLevelHeading);
    // then
    final MarkdownConversionException actualException = assertThrows(MarkdownConversionException.class, action);
    assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to convert Markdown " + irrelevantMarkdown));
    assertThat("Cause highlights argument validation error.", actualException.getCause().getMessage(), is("Argument topHeadingLevel has to be greater than or equal to zero but was " + illegalTopLevelHeading));
}
Also used : MarkdownConversionException(uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException) RandomTestUtils.randomString(uk.nhs.digital.test.util.RandomTestUtils.randomString) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 3 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project sonarqube by SonarSource.

the class WebServerTest method main_givenNoArguments.

@Test
public void main_givenNoArguments() {
    String[] arguments = {};
    ThrowingRunnable runnable = () -> WebServer.main(arguments);
    Assert.assertThrows("Only a single command-line argument is accepted (absolute path to configuration file)", IllegalArgumentException.class, runnable);
}
Also used : ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 4 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestAdd method addNullValue.

@Test
public void addNullValue() {
    Version version = Version.getServerVersion(client, null);
    // Do not run on servers < 3.6.1
    if (version.isLess(3, 6, 1)) {
        return;
    }
    Key key = new Key(args.namespace, args.set, "addkey");
    String binName = args.getBinName("addbin");
    // Delete record if it already exists.
    client.delete(null, key);
    Bin bin = new Bin(binName, (Long) null);
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.add(null, key, bin);
        }
    });
    assertEquals(ae.getResultCode(), ResultCode.PARAMETER_ERROR);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Version(com.aerospike.client.util.Version) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 5 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestOperateMap method operateMapRemoveByKeyListForNonExistingKey.

@Test
public void operateMapRemoveByKeyListForNonExistingKey() throws Exception {
    Key key = new Key(args.namespace, args.set, "opmkey13");
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.operate(null, key, MapOperation.removeByKeyList(binName, singletonList(Value.get("key-1")), MapReturnType.VALUE));
        }
    });
    assertEquals(ae.getResultCode(), ResultCode.KEY_NOT_FOUND_ERROR);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Aggregations

ThrowingRunnable (org.junit.function.ThrowingRunnable)48 Test (org.junit.Test)47 AerospikeException (com.aerospike.client.AerospikeException)41 WritePolicy (com.aerospike.client.policy.WritePolicy)34 Record (com.aerospike.client.Record)32 BatchPolicy (com.aerospike.client.policy.BatchPolicy)28 Policy (com.aerospike.client.policy.Policy)28 Expression (com.aerospike.client.exp.Expression)5 Bin (com.aerospike.client.Bin)3 Key (com.aerospike.client.Key)2 Options (com.github.jknack.handlebars.Options)2 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)2 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 Version (com.aerospike.client.util.Version)1 Matchers.anyDrawable (com.bumptech.glide.test.Matchers.anyDrawable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MarkdownConversionException (uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException)1