org.hamcrest.core.CombinableMatcher Java Examples

The following examples show how to use org.hamcrest.core.CombinableMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssertTests.java    From android-testing-guide with MIT License 5 votes vote down vote up
@Test
public void testAssertThatHamcrestCoreMatchers() {
    assertThat("good", allOf(equalTo("good"), startsWith("good")));
    assertThat("good", not(allOf(equalTo("bad"), equalTo("good"))));
    assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
    assertThat(7, not(CombinableMatcher.either(equalTo(3)).or(equalTo(4))));
    assertThat(new Object(), not(sameInstance(new Object())));
}
 
Example #2
Source File: AssertTests.java    From Advanced_Java with MIT License 5 votes vote down vote up
@Test
public void testAssertThatHamcrestCoreMatchers() {
    assertThat("good", allOf(equalTo("good"), startsWith("good")));
    assertThat("good", not(allOf(equalTo("bad"), equalTo("good"))));
    assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
    assertThat(7, not(CombinableMatcher.<Integer> either(equalTo(3)).or(equalTo(4))));
    assertThat(new Object(), not(sameInstance(new Object())));
}
 
Example #3
Source File: UpfrontAllocatingPageSourceTest.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void testReallyLargeUpfrontAllocation() {
  try {
    new UpfrontAllocatingPageSource(new OffHeapBufferSource(), Long.MAX_VALUE, MemoryUnit.GIGABYTES.toBytes(1));
    Assert.fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException e) {
    Assert.assertThat(e.getMessage(), CombinableMatcher.either(containsString("physical memory")).or(containsString("allocate more off-heap memory")));
  }
}
 
Example #4
Source File: ExpectedConstraintViolation.java    From testfun with Apache License 2.0 5 votes vote down vote up
/**
 * Adds {@code matcher} to the list of requirements for any thrown exception.
 */
// Should be able to remove this suppression in some brave new hamcrest world.
@SuppressWarnings("unchecked")
public void expect(Matcher<?> matcher) {
    if (this.matcher == null) {
        this.matcher = (Matcher<Object>) matcher;
    } else {
        this.matcher = CombinableMatcher.both(this.matcher).and((Matcher<Object>) matcher);
    }
}
 
Example #5
Source File: ExpectedConstraintViolation.java    From testfun with Apache License 2.0 5 votes vote down vote up
/**
 * Adds to the list of requirements for any thrown exception that it
 * should <em>contain</em> string {@code substring}
 */
public void expectViolation(String substring) {
    if (matcher == null) {
        expect(CombinableMatcher.either(
                new CausedBy(org.hibernate.exception.ConstraintViolationException.class))
                .or(new CausedBy(ConstraintViolationException.class)));
    }

    expectMessage(CoreMatchers.containsString(substring));
}
 
Example #6
Source File: PdfFileSourceAdapterTest.java    From sejda with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void windowsFileWithPassword() {
    PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf:secret123").getPdfFileSource();
    assertThat(result.getPassword(), is("secret123"));
    assertThat(result.getSource(),
            CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or(
                    is(new File("c:\\tmp\\inputFile1.pdf"))));
}
 
Example #7
Source File: PdfFileSourceAdapterTest.java    From sejda with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void windowsFileNoPassword() {
    PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf").getPdfFileSource();
    assertNull(result.getPassword());
    assertThat(result.getSource(),
            CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or(
                    is(new File("c:\\tmp\\inputFile1.pdf"))));
}
 
Example #8
Source File: PdfFileSourceAdapterTest.java    From sejda with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void protectedFileWithPasswordContainingSeparator() {
    PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf:secret.pdf:password").getPdfFileSource();
    assertThat(result.getPassword(), is("secret.pdf:password"));
    assertThat(result.getSource(),
            CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or(
                    is(new File("c:\\tmp\\inputFile1.pdf"))));
}