Search in sources :

Example 21 with ThrowingRunnable

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

the class TestFilterExp method filterMod.

@Test
public void filterMod() {
    Policy policy = new Policy();
    policy.filterExp = Exp.build(Exp.eq(Exp.mod(Exp.intBin(binA), Exp.val(2)), Exp.val(0)));
    policy.failOnFilteredOut = true;
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.get(policy, keyA);
        }
    });
    assertEquals(ResultCode.FILTERED_OUT, ae.getResultCode());
    Record r = client.get(policy, keyB);
    assertBinEqual(keyA, r, binA, 2);
}
Also used : Policy(com.aerospike.client.policy.Policy) BatchPolicy(com.aerospike.client.policy.BatchPolicy) WritePolicy(com.aerospike.client.policy.WritePolicy) AerospikeException(com.aerospike.client.AerospikeException) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 22 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project hutool by looly.

the class Ipv4UtilTest method getMaskBitByIllegalMaskTest.

@Test
public void getMaskBitByIllegalMaskTest() {
    ThrowingRunnable getMaskBitByMaskRunnable = () -> Ipv4Util.getMaskBitByMask("255.255.0.255");
    Assert.assertThrows("非法掩码测试", IllegalArgumentException.class, getMaskBitByMaskRunnable);
}
Also used : ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 23 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project copybara by google.

the class GitMirrorTest method testMergeConflict.

@Test
public void testMergeConflict() throws Exception {
    Migration mirror = mergeInit();
    GitLogEntry destChange = repoChange(destRepo, "some_file", "Hello", "destination only");
    GitLogEntry originChange = repoChange(originRepo, "some_file", "Bye", "new change");
    assertThat((assertThrows(ValidationException.class, new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            mirror.run(workdir, ImmutableList.of());
        }
    }))).hasMessageThat().contains("Conflict merging refs/heads/" + primaryBranch);
}
Also used : Migration(com.google.copybara.config.Migration) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 24 with ThrowingRunnable

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

the class HeadingsHyperlinksFromMarkdownHelperTest method throwsException_onRenderingFailure.

@Test
public void throwsException_onRenderingFailure() {
    // given
    final Options options = mock(Options.class);
    final RuntimeException expectedCause = new RuntimeException();
    given(options.buffer()).willThrow(expectedCause);
    final String irrelevantMarkdown = "Irrelevant `Markdown`.";
    // when
    final ThrowingRunnable action = () -> helper.apply(irrelevantMarkdown, options);
    // then
    final TemplateRenderingException actualException = assertThrows(TemplateRenderingException.class, action);
    assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to render hyperlinks for headings from Markdown " + irrelevantMarkdown + "."));
    assertThat("Cause exception is included.", actualException.getCause(), sameInstance(expectedCause));
}
Also used : Options(com.github.jknack.handlebars.Options) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 25 with ThrowingRunnable

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

the class MarkdownHelperTest method throwsException_onMarkdownRenderingFailure.

@Test
public void throwsException_onMarkdownRenderingFailure() {
    // given
    final RuntimeException expectedCause = new RuntimeException();
    given(commonmarkMarkdownConverter.toHtml(any(), any(), any(Integer.class))).willThrow(expectedCause);
    final Options options = OptionsStub.empty();
    final String markdown = "some markdown";
    // when
    final ThrowingRunnable action = () -> markdownHelper.apply(markdown, options);
    // then
    final RuntimeException actualException = assertThrows(RuntimeException.class, action);
    assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to render Markdown: " + markdown));
    assertThat("Cause exception is included.", actualException.getCause(), sameInstance(expectedCause));
}
Also used : Options(com.github.jknack.handlebars.Options) RandomTestUtils.randomString(uk.nhs.digital.test.util.RandomTestUtils.randomString) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Aggregations

ThrowingRunnable (org.junit.function.ThrowingRunnable)49 Test (org.junit.Test)48 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 Migration (com.google.copybara.config.Migration)1 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MarkdownConversionException (uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException)1