@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()))); }
@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()))); }
@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"))); } }
@Test public void testShortPeriodSampler() throws InterruptedException { StatisticArchive<Integer> archive = new StatisticArchive<>(20); StatisticSampler<Integer> sampler = new StatisticSampler<>(100L, TimeUnit.MILLISECONDS, constant(GAUGE, 42), archive); try { sampler.start(); TimeUnit.SECONDS.sleep(1); assertBy(1, TimeUnit.SECONDS, contentsOf(archive), hasSize(CombinableMatcher.both(greaterThan(10)).and(lessThan(20)))); } finally { sampler.shutdown(); } }
@Test public void testBothMatcher() throws Exception { Matcher<String> matcher = CombinableMatcher.both(equalTo("abc")).and(equalTo("bc")); assertDescription(matcher, "('abc' and 'bc')"); assertMismatch("abc", matcher, "'bc' was 'abc'"); }
/** * 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); } }
/** * 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)); }
@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")))); }
@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")))); }
@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")))); }
public static CombinableMatcher<? super IDataSourceConfiguration> isThisTestSource() { return both(hasName(equalTo(THIS_SOURCE_NAME)))// .and(hasUri(equalTo(THIS_SOURCE_URI))) .and(hasLanguages(containsInAnyOrder(EN, DE))) .and(hasRank(closeTo(THIS_SOURCE_RANK, TOLERANCE))); }
public static CombinableMatcher<? super IDataSourceConfiguration> isThatTestSource() { return both(hasName(equalTo(THAT_SOURCE_NAME)))// .and(hasUri(equalTo(THAT_SOURCE_URI))) .and(hasLanguages(containsInAnyOrder(EN))) .and(hasRank(closeTo(THAT_SOURCE_RANK, TOLERANCE))); }