package com.govpaynet.rest.validator.marionco; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.validation.Errors; import com.govpaynet.rest.integration.GenericResponseCode; import com.govpaynet.rest.model.CheckUTTRequest; import com.govpaynet.validator.model.Validator; public class CheckUTTValidator implements Validator<checkuttrequest> { private final Logger logger = LoggerFactory .getLogger(CheckUTTValidator.class); public final void validate(final Object obj, final Errors errors) { final CheckUTTRequest input = (CheckUTTRequest)obj; if (input.getInputValue().isEmpty()){ logger.debug("The user input data."); errors.rejectValue(GenericResponseCode.GENERIC_200.value(),"Invalid request data."); } return; } @Override public final Boolean supports(final Classreturn inputType != null && CheckUTTRequest.class.isAssignableFrom(inputType); } }
package com.govpaynet.rest.validator.marionco; import static org.junit.Assert.*; import org.easymock.Capture; import org.junit.Before; import org.junit.Test; import org.springframework.validation.Errors; import com.govpaynet.rest.integration.GenericResponseCode; import com.govpaynet.rest.model.CheckUTTRequest; public class CheckUTTValidatorTest { private CheckUTTValidator validator; private CheckUTTRequest request; private Errors errorsMock; @Before public void setup(){ //request=new CheckUTTRequest(); request.setUserInputValue(null, null); request=creakeMock(CheckUTTValidator.class); errorsMock= createMock(Errors.class); validator=new CheckUTTValidator(); } @Test public void supportsNot() { assertFalse(validator.supports(null)); } @Test public void supports() { try{ assertTrue(validator.supports(CheckUTTRequest.class)); } catch(NullPointerException e){ } } @Test public void validateEmptyCheckUTTUserInput() { GenericResponseCode expectedErroCode = GenericResponseCode.GENERIC_200; final Capture<string> errorCode = new Capture<string>(); try { request.setUserInputValue(null, null); validator.validate(request, errorsMock); assertEquals(expectedErroCode, errorCode.getValue()); } catch (NullPointerException e) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)