Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

ngeor/yak4j-spring-test-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yak4j-spring-test-utils

Testing utilities for Spring

Maven Central Java CI with Maven javadoc

Archived project! This project is archived and will be removed. It has moved here.

Overview

yak shaving for Java: Testing utilities for Spring

The package offers custom assertions for easier testing with Spring. Assertions are built on top of assertJ.

RequestEntity

import static com.github.ngeor.yak4j.Assertions.assertThat;

RequestEntity<String> requestEntity = RequestEntity
    .post(URI.create("http://localhost/"))
    .accept(MediaType.APPLICATION_JSON)
    .contentType(MediaType.APPLICATION_JSON)
    .header("Authorization", "Basic 1234")
    .body("hello world");

assertThat(requestEntity)
    .hasMethod(HttpMethod.POST)
    .hasUrl("http://localhost/")
    .hasJsonAcceptAndContentTypeHeaders()
    .hasAuthorizationHeader("Basic 1234")
    .hasBody("hello world");

ResponseEntity

Checking of status and body:

import static com.github.ngeor.yak4j.Assertions.assertThat;

ResponseEntity<String> responseEntity = ResponseEntity.ok("hello world");

assertThat(responseEntity)
    .isOk() // check status = 200
    .hasBody("hello world"); // check body

ResultActions

Checking status:

import static com.github.ngeor.yak4j.Assertions.assertThat;

ResultActions resultActions = mockMvc.perform(/* do the mock MVC call */);

assertThat(resultActions)
    .isOk() // check status = 200

Checking for validation errors:

import static com.github.ngeor.yak4j.InvalidFieldExpectationBuilder.invalidField;

assertThat(resultActions)
    .isBadRequest( // check status = 400
        invalidField("name", "NotNull") // check these validation errors
    );

About

Testing utilities for Spring

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published