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);
}
});
}
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));
}
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);
}
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);
}
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);
}
Aggregations