Create RegistrationPayloadTests

First of all, let's create the com.taskagile.web.payload.RegistrationPayloadTests unit test class. In this test class, we will create an instance of javax.validation.Validator to perform data validation. We will still follow the [UnitOfWork_StateUnderTest_ExpectedBehavior] convention for naming the test methods. Here is how the RegistrationPayloadTests looks:

...
public class RegistrationPayloadTests {

private Validator validator;

@Before
public void setup () {
ValidatorFactory factory =
Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}

@Test
public void validate_blankPayload_shouldFail() {
RegistrationPayload payload = new RegistrationPayload();
Set<ConstraintViolation<RegistrationPayload>> violations =
validator.validate(payload);
assertEquals(3, violations.size());
}
}

As you can see, we create an instance of javax.validation.Validator in the setup() method, which is annotated with the @Before annotation so that it will be executed before running each test method. It is like beforeEach() in Jest. The first test method we have here is quite simple. It tests a blank registration form, and we're expecting to see three constraint violations. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.107.25