Preyea Regmi
5 years ago
5 changed files with 221 additions and 63 deletions
-
142app/src/main/java/com/gmeremit/online/gmeremittance_native/recipientV3/model/recipientaddV3/ValidationRuleModel.java
-
6app/src/main/java/com/gmeremit/online/gmeremittance_native/recipientV3/presenter/recipientaddV3/AddRecipientV3ValidationExecutor.java
-
2app/src/main/java/com/gmeremit/online/gmeremittance_native/recipientV3/presenter/recipientaddV3/RecipientAddV3Presenter.java
-
14app/src/test/java/com/gmeremit/online/gmeremittance_native/AddRecipientV3ValidationExecutorTester.java
-
120app/src/test/java/com/gmeremit/online/gmeremittance_native/ValidationRuleTest.java
@ -0,0 +1,120 @@ |
|||
package com.gmeremit.online.gmeremittance_native; |
|||
|
|||
import com.gmeremit.online.gmeremittance_native.recipientV3.model.recipientaddV3.ValidationRuleModel; |
|||
|
|||
import org.junit.Test; |
|||
import org.mockito.Mockito; |
|||
|
|||
import static org.junit.Assert.assertEquals; |
|||
import static org.junit.Assert.assertNull; |
|||
|
|||
|
|||
public class ValidationRuleTest { |
|||
|
|||
public static final String SOME_RANDOM_STRING_VALUE = "Some random value"; |
|||
public static final String EMPTY_STRING_VALUE = ""; |
|||
public static final String EMPTY_NULL_VALUE = null; |
|||
|
|||
public static final String SOME_RANDOM_STRING_WITH_KNOWN_LENGTH = "So Fine"; |
|||
public static final int FIELD_LENGTH_LOWER_BOUND=3; |
|||
public static final String SOME_RANDOM_STRING_WITH_LENGTH_LESS_THAN_LOWER_BOUND="So"; |
|||
public static final String SOME_RANDOM_STRING_WITH_LENGTH_GREATER_THAN_UPPER_BOUND="So Fine, Is it"; |
|||
public static final int FIELD_LENGTH_UPPER_BOUND=5; |
|||
|
|||
public static final String FIELD_IS_REQUIRED_ERROR_MESSAGE = "Field is required"; |
|||
public static final String FIELD_LENGTH_IS_LESS_ERROR_MESSAGE = "Field length is less than expected"; |
|||
public static final String FIELD_LENGTH_IS_GREATER_ERROR_MESSAGE = "Field length is greater than expected"; |
|||
public static final boolean FIELD_REQUIRED_FALSE = false; |
|||
public static final boolean FIELD_REQUIRED_TRUE = true; |
|||
|
|||
|
|||
@Test |
|||
public void validateAll_Should_Return_NULL_When_Field_Required_Flag_Is_False() { |
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagFalse = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_FALSE, -1, 2, "", false); |
|||
assertNull("Should return NULL when field required flag is " + FIELD_REQUIRED_FALSE, validationRuleWithFieldRequiredFlagFalse.validateValueAndReturnErrorMessageOnFail(SOME_RANDOM_STRING_VALUE)); |
|||
|
|||
} |
|||
|
|||
@Test |
|||
public void validateAll_Should_Return_Field_Is_Required_Error_Message_When_Field_Required_Flag_Is_True() { |
|||
|
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagTrue = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_TRUE, -1, 2, "", false); |
|||
|
|||
ValidationRuleModel rule = Mockito.spy(validationRuleWithFieldRequiredFlagTrue ); |
|||
|
|||
Mockito.when(rule.getFieldIsRequiredErrorMessage()).thenReturn(FIELD_IS_REQUIRED_ERROR_MESSAGE); |
|||
|
|||
assertEquals("Should return field require error message: " + FIELD_IS_REQUIRED_ERROR_MESSAGE, |
|||
FIELD_IS_REQUIRED_ERROR_MESSAGE, rule.validateValueAndReturnErrorMessageOnFail(EMPTY_STRING_VALUE) |
|||
); |
|||
assertEquals("Should return field require error message: " + FIELD_IS_REQUIRED_ERROR_MESSAGE, |
|||
FIELD_IS_REQUIRED_ERROR_MESSAGE, rule.validateValueAndReturnErrorMessageOnFail(EMPTY_NULL_VALUE) |
|||
); |
|||
|
|||
} |
|||
@Test |
|||
public void validateAll_Should_Return_NULL_When_Passed_Value_Is_Greater_Or_Equal_To_Min_Val_Required() { |
|||
|
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagTrue = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_TRUE, -1, FIELD_LENGTH_LOWER_BOUND, "", false); |
|||
|
|||
// ValidationRuleModel rule = Mockito.spy(validationRuleWithFieldRequiredFlagTrue ); |
|||
// |
|||
// Mockito.when(rule.getFieldIsRequiredErrorMessage()).thenReturn(FIELD_IS_REQUIRED_ERROR_MESSAGE); |
|||
|
|||
assertNull("Should return NULL when passes param length i.e. "+ SOME_RANDOM_STRING_WITH_KNOWN_LENGTH.length() +" is greater than "+FIELD_LENGTH_LOWER_BOUND, |
|||
validationRuleWithFieldRequiredFlagTrue.validateValueAndReturnErrorMessageOnFail(SOME_RANDOM_STRING_WITH_KNOWN_LENGTH) |
|||
); |
|||
|
|||
} |
|||
|
|||
|
|||
@Test |
|||
public void validateAll_Should_Return_Lower_Bound_Error_Message_When_Passed_Value_Is_Less_Than_Min_Val_Required() { |
|||
|
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagTrue = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_TRUE, -1, FIELD_LENGTH_LOWER_BOUND, "", false); |
|||
|
|||
ValidationRuleModel rule = Mockito.spy(validationRuleWithFieldRequiredFlagTrue); |
|||
|
|||
Mockito.when(rule.getFieldLengthIsLessThanLowerBoundDefinedErrorMessage()).thenReturn(FIELD_LENGTH_IS_LESS_ERROR_MESSAGE); |
|||
|
|||
assertEquals( |
|||
"Should return lower bound error message: " + FIELD_LENGTH_IS_LESS_ERROR_MESSAGE+ " for data: "+ SOME_RANDOM_STRING_WITH_KNOWN_LENGTH +" with lower bound defined: "+FIELD_LENGTH_LOWER_BOUND, |
|||
FIELD_LENGTH_IS_LESS_ERROR_MESSAGE, rule.validateValueAndReturnErrorMessageOnFail(SOME_RANDOM_STRING_WITH_LENGTH_LESS_THAN_LOWER_BOUND) |
|||
); |
|||
|
|||
|
|||
} |
|||
|
|||
@Test |
|||
public void validateAll_Should_Return_NULL_When_Passed_Value_Is_Less_Or_Equal_To_Max_Val_Required() { |
|||
|
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagTrue = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_TRUE, FIELD_LENGTH_UPPER_BOUND, FIELD_LENGTH_LOWER_BOUND, "", false); |
|||
|
|||
// ValidationRuleModel rule = Mockito.spy(validationRuleWithFieldRequiredFlagTrue ); |
|||
// |
|||
// Mockito.when(rule.getFieldIsRequiredErrorMessage()).thenReturn(FIELD_IS_REQUIRED_ERROR_MESSAGE); |
|||
|
|||
assertNull("Should return NULL when passes param length i.e. "+ SOME_RANDOM_STRING_WITH_KNOWN_LENGTH.length() +" is lesser or equal to "+FIELD_LENGTH_UPPER_BOUND, |
|||
validationRuleWithFieldRequiredFlagTrue.validateValueAndReturnErrorMessageOnFail(SOME_RANDOM_STRING_WITH_KNOWN_LENGTH) |
|||
); |
|||
|
|||
} |
|||
|
|||
@Test |
|||
public void validateAll_Should_Return_Upper_Bound_Error_Message_When_Passed_Value_Is_Greater_Than_MAx_Val_Required() { |
|||
|
|||
ValidationRuleModel validationRuleWithFieldRequiredFlagTrue = new ValidationRuleModel(0, "Full name", FIELD_REQUIRED_TRUE, FIELD_LENGTH_UPPER_BOUND, FIELD_LENGTH_LOWER_BOUND, "", false); |
|||
|
|||
ValidationRuleModel rule = Mockito.spy(validationRuleWithFieldRequiredFlagTrue); |
|||
|
|||
Mockito.when(rule.getFieldLengthIsGreaterThanUpperBoundDefinedErrorMessage()).thenReturn(FIELD_LENGTH_IS_GREATER_ERROR_MESSAGE); |
|||
|
|||
assertEquals( |
|||
"Should return upper bound error message. for Data: \'"+ SOME_RANDOM_STRING_WITH_LENGTH_GREATER_THAN_UPPER_BOUND +"\' length: "+SOME_RANDOM_STRING_WITH_LENGTH_GREATER_THAN_UPPER_BOUND.length()+" with upper bound defined: "+FIELD_LENGTH_UPPER_BOUND, |
|||
FIELD_LENGTH_IS_GREATER_ERROR_MESSAGE, rule.validateValueAndReturnErrorMessageOnFail(SOME_RANDOM_STRING_WITH_LENGTH_GREATER_THAN_UPPER_BOUND) |
|||
); |
|||
|
|||
|
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue