Java Code Examples for org.hamcrest.MatcherAssert#assertThat()

The following examples show how to use org.hamcrest.MatcherAssert#assertThat() . 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: GetHeadersFromPeerByNumberTaskTest.java    From besu with Apache License 2.0 6 votes vote down vote up
@Test
public void checkThatSequentialHeadersFormingAChainWorks() {
  final BlockHeader block1 =
      new BlockHeaderTestFixture().number(1).parentHash(generateTestBlockHash(0)).buildHeader();
  final BlockHeader block2 =
      new BlockHeaderTestFixture().number(2).parentHash(block1.getHash()).buildHeader();
  final List<BlockHeader> headers = Arrays.asList(block1, block2);
  final AbstractGetHeadersFromPeerTask task =
      new GetHeadersFromPeerByNumberTask(
          protocolSchedule, ethContext, block1.getNumber(), 2, 0, false, metricsSystem);
  Optional<List<BlockHeader>> optionalBlockHeaders =
      task.processResponse(false, BlockHeadersMessage.create(headers), peerMock);
  assertThat(optionalBlockHeaders).isNotNull();
  assertThat(optionalBlockHeaders).isPresent();
  List<BlockHeader> blockHeaders = optionalBlockHeaders.get();
  MatcherAssert.assertThat(blockHeaders, hasSize(2));
  verify(peerMock, times(0)).disconnect(any());
}
 
Example 2
Source File: PutTest.java    From verano-http with MIT License 6 votes vote down vote up
@Test
public void buildsEmptyPutRequest() {
    final Dict dict = new Put();
    MatcherAssert.assertThat(
        new CollectionOf<>(dict).size(),
        new IsEqual<>(2)
    );
    MatcherAssert.assertThat(
        dict.get("method"),
        new IsEqual<>("PUT")
    );
    MatcherAssert.assertThat(
        dict.get("path").isEmpty(),
        new IsEqual<>(true)
    );
}
 
Example 3
Source File: PostTest.java    From verano-http with MIT License 6 votes vote down vote up
@Test
public void buildsEmptyPostRequest() {
    final Dict dict = new Post();
    MatcherAssert.assertThat(
        new CollectionOf<>(dict).size(),
        new IsEqual<>(2)
    );
    MatcherAssert.assertThat(
        dict.get("method"),
        new IsEqual<>("POST")
    );
    MatcherAssert.assertThat(
        dict.get("path").isEmpty(),
        new IsEqual<>(true)
    );
}
 
Example 4
Source File: TestInit.java    From jbang with MIT License 5 votes vote down vote up
@Test
void testCli(@TempDir Path outputDir) throws IOException {

	Path x = outputDir.resolve("edit.java");
	String s = x.toString();
	Jbang.getCommandLine().execute("init", "--template=cli", s);
	assertThat(new File(s).exists(), is(true));

	MatcherAssert.assertThat(Util.readString(x), containsString("picocli"));

}
 
Example 5
Source File: DtoBodyTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesDtoBodyToRequest() {
    final Dto dto = new Dto();
    dto.setProperty("prop");
    MatcherAssert.assertThat(
        new DtoBody(dto).apply(new HashDict()).get("body"),
        new IsEqual<>("{\"property\":\"prop\"}")
    );
}
 
Example 6
Source File: PostMatchTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void matchesPostMethod() {
    final String body = "some body";
    MatcherAssert.assertThat(
        new PostMatch(
            new BodyMatch(new IsEqual<>(body))
        ).apply(
            new HashDict(
                new KvpOf("body", body),
                new KvpOf("method", "POST")
            )
        ).isEmpty(),
        new IsEqual<>(true)
    );
}
 
Example 7
Source File: MethodOfTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void extractsMethodFromDict() {
    final String method = "GET";
    MatcherAssert.assertThat(
        new Method.Of(
            new HashDict(
                new KvpOf("method", method), new KvpOf("unknown", "")
            )
        ).asString(),
        new IsEqual<>(method)
    );
}
 
Example 8
Source File: QueryParamsTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesQueryParamsToRequest() {
    final String value = "value";
    MatcherAssert.assertThat(
        new QueryParams(new QueryParam("key", value))
            .apply(new HashDict()).get("q.key"),
        new IsEqual<>(value)
    );
}
 
Example 9
Source File: QueryParamTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesQueryParamToRequest() {
    final String value = "value";
    MatcherAssert.assertThat(
        new QueryParam("key", value).apply(new HashDict()).get("q.key"),
        new IsEqual<>(value)
    );
}
 
Example 10
Source File: FormParamsOfTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void buildsFormParamsInput() {
    MatcherAssert.assertThat(
        new FormParams.Of(
            new HashDict(
                new KvpOf("f.name", "John"),
                new KvpOf("f.surname", "Smith")
            )
        ).asString(),
        new IsEqual<>("name=John&surname=Smith")
    );
}
 
Example 11
Source File: StatusTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesStatusToResponse() {
    MatcherAssert.assertThat(
        new Status(200).apply(new HashDict()).get("status"),
        new IsEqual<>("200")
    );
}
 
Example 12
Source File: CookieTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void addsContentTypeHeaderToRequest() {
    final String value = "text/html";
    MatcherAssert.assertThat(
        new Cookie(value)
            .apply(new HashDict())
            .get("h.Cookie"),
        new IsEqual<>(value)
    );
}
 
Example 13
Source File: MethodTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesMethodToRequest() {
    final String method = "GET";
    MatcherAssert.assertThat(
        new Method(method).apply(new HashDict()).get("method"),
        new IsEqual<>(method)
    );
}
 
Example 14
Source File: AcceptTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void addsAcceptHeaderToRequest() {
    final String value = "text/html";
    MatcherAssert.assertThat(
        new Accept(value)
            .apply(new HashDict())
            .get("h.Accept"),
        new IsEqual<>(value)
    );
}
 
Example 15
Source File: JsonBodyOfTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void extractsJsonObjectFromDict() {
    MatcherAssert.assertThat(
        new JsonBody.Of(
            new HashDict(
                new KvpOf("body", "{}"),
                new KvpOf("unknown", "")
            )
        ).json(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example 16
Source File: PutMatchTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void matchesPutMethod() {
    final String body = "some body";
    MatcherAssert.assertThat(
        new PutMatch(
            new BodyMatch(new IsEqual<>(body))
        ).apply(
            new HashDict(
                new KvpOf("body", body),
                new KvpOf("method", "PUT")
            )
        ).isEmpty(),
        new IsEqual<>(true)
    );
}
 
Example 17
Source File: ProxyTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appendsProxyToClient() {
    final HttpClientBuilder builder = HttpClients.custom();
    MatcherAssert.assertThat(
        new Proxy("localhost", 8080).apply(builder),
        new IsEqual<>(builder)
    );
    MatcherAssert.assertThat(
        builder.build(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example 18
Source File: RequestUriTest.java    From verano-http with MIT License 5 votes vote down vote up
@Test
public void appliesRequestUriToRequest() {
    final String uri = "www.example.com";
    MatcherAssert.assertThat(
        new RequestUri(uri)
            .apply(new HashDict()).get("uri"),
        new IsEqual<>(uri)
    );
}
 
Example 19
Source File: SpendReportTest.java    From flink-playgrounds with Apache License 2.0 5 votes vote down vote up
@Test
public void testReport() {
    EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build();
    TableEnvironment tEnv = TableEnvironment.create(settings);

    Table transactions =
            tEnv.fromValues(
                    DataTypes.ROW(
                            DataTypes.FIELD("account_id", DataTypes.BIGINT()),
                            DataTypes.FIELD("amount", DataTypes.BIGINT()),
                            DataTypes.FIELD("transaction_time", DataTypes.TIMESTAMP(3))),
                    Row.of(1, 188, DATE_TIME.plusMinutes(12)),
                    Row.of(2, 374, DATE_TIME.plusMinutes(47)),
                    Row.of(3, 112, DATE_TIME.plusMinutes(36)),
                    Row.of(4, 478, DATE_TIME.plusMinutes(3)),
                    Row.of(5, 208, DATE_TIME.plusMinutes(8)),
                    Row.of(1, 379, DATE_TIME.plusMinutes(53)),
                    Row.of(2, 351, DATE_TIME.plusMinutes(32)),
                    Row.of(3, 320, DATE_TIME.plusMinutes(31)),
                    Row.of(4, 259, DATE_TIME.plusMinutes(19)),
                    Row.of(5, 273, DATE_TIME.plusMinutes(42)));

    try {
        TableResult results = SpendReport.report(transactions).execute();

        MatcherAssert.assertThat(
                materialize(results),
                Matchers.containsInAnyOrder(
                        Row.of(1L, DATE_TIME, 567L),
                        Row.of(2L, DATE_TIME, 725L),
                        Row.of(3L, DATE_TIME, 432L),
                        Row.of(4L, DATE_TIME, 737L),
                        Row.of(5L, DATE_TIME, 481L)));
    } catch (UnimplementedException e) {
        Assume.assumeNoException("The walkthrough has not been implemented", e);
    }
}
 
Example 20
Source File: XpathExpectationsHelper.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Apply the XPath expression and assert the resulting content with the
 * given Hamcrest matcher.
 * @throws Exception if content parsing or expression evaluation fails
 */
public void assertNumber(byte[] content, @Nullable String encoding, Matcher<? super Double> matcher) throws Exception {
	Double actual = evaluateXpath(content, encoding, Double.class);
	MatcherAssert.assertThat("XPath " + this.expression, actual, matcher);
}