1

I am using hamcrest for first time, i have developed a framework to validate particular JSON field values need to satisfy some business rules, i am trying to check on of the field in JSON should not be " " or null. Please find below for the code,matcherOperator validate JSON field against a Array of values for example in ISINARRAY validate the JSON filed is present in the following list of array values [1,2,3,4] similarly NOTINARRAY validate the JSON filed should not be present given range of array values. I am trying to check whether given field is empty or null i defined array like this [null,""] and using NOTINARRAY to check JSON key value shouldn't be null or "" for null its working but the JSON value is "" its validating to true and i tried using Matchers.blankOrNullString() too but its not working and i saw two question of similar type but they are part of JUNIT testing which i tried to used but not working below are the question i referred

Hamcrest matcher with slashes is interpreted as a part of validation

Hamcrest check if value is null or empty array

 public <T extends Comparable<T>> Matcher<String> mymatcher(final FieldOperator matcherOperator,
                                                                final List<String> value) 
   {

        switch (matcherOperator) {

            case ISINARRAY: {
                return Matchers.in(value);
            }
            case NOTINARRAY: {

                return Matchers.not(Matchers.in(value));
            }

    } 

I am not sure where i am doing wrong please help me in solving the issue.

YRK
  • 153
  • 1
  • 1
  • 22

0 Answers0