@ -19,6 +19,7 @@ import static com.jayway.jsonpath.internal.Utils.notNull;
/ * *
*
* /
@SuppressWarnings ( "unchecked" )
public class Criteria implements Predicate {
private static final Logger logger = LoggerFactory . getLogger ( Criteria . class ) ;
@ -173,10 +174,8 @@ public class Criteria implements Predicate {
boolean eval ( Object expected , Object actual , Configuration configuration ) {
final Class < ? > expType = ( Class < ? > ) expected ;
final Class < ? > actType = actual = = null ? null : actual . getClass ( ) ;
if ( actType ! = null ) {
return expType . isAssignableFrom ( actType ) ;
}
return false ;
return actType ! = null & & expType . isAssignableFrom ( actType ) ;
}
} ,
REGEX {
@ -272,10 +271,17 @@ public class Criteria implements Predicate {
if ( CriteriaType . EXISTS = = criteriaType ) {
boolean exists = ( ( Boolean ) expected ) ;
try {
path . evaluate ( model , configuration . options ( Option . THROW_ON_MISSING_PROPERTY ) ) . getValue ( ) ;
return exists = = true ;
//path.evaluate(model, configuration.options(Option.THROW_ON_MISSING_PROPERTY)).getValue();
Configuration c = configuration ;
if ( c . containsOption ( Option . ALWAYS_RETURN_LIST ) | | c . containsOption ( Option . SUPPRESS_EXCEPTIONS ) ) {
c = c . options ( ) ;
}
path . evaluate ( model , c ) . getValue ( ) ;
return exists ;
} catch ( PathNotFoundException e ) {
return exists = = false ;
return ! exists ;
}
} else {
@ -326,7 +332,7 @@ public class Criteria implements Predicate {
* Creates a criterion using equality
*
* @param o
* @return
* @return the criteria
* /
public Criteria is ( Object o ) {
this . criteriaType = CriteriaType . EQ ;
@ -338,7 +344,7 @@ public class Criteria implements Predicate {
* Creates a criterion using equality
*
* @param o
* @return
* @return the criteria
* /
public Criteria eq ( Object o ) {
return is ( o ) ;
@ -348,7 +354,7 @@ public class Criteria implements Predicate {
* Creates a criterion using the < b > ! = < / b > operator
*
* @param o
* @return
* @return the criteria
* /
public Criteria ne ( Object o ) {
this . criteriaType = CriteriaType . NE ;
@ -360,7 +366,7 @@ public class Criteria implements Predicate {
* Creates a criterion using the < b > & lt ; < / b > operator
*
* @param o
* @return
* @return the criteria
* /
public Criteria lt ( Object o ) {
this . criteriaType = CriteriaType . LT ;
@ -372,7 +378,7 @@ public class Criteria implements Predicate {
* Creates a criterion using the < b > & lt ; = < / b > operator
*
* @param o
* @return
* @return the criteria
* /
public Criteria lte ( Object o ) {
this . criteriaType = CriteriaType . LTE ;
@ -384,7 +390,7 @@ public class Criteria implements Predicate {
* Creates a criterion using the < b > & gt ; < / b > operator
*
* @param o
* @return
* @return the criteria
* /
public Criteria gt ( Object o ) {
this . criteriaType = CriteriaType . GT ;
@ -396,7 +402,7 @@ public class Criteria implements Predicate {
* Creates a criterion using the < b > & gt ; = < / b > operator
*
* @param o
* @return
* @return the criteria
* /
public Criteria gte ( Object o ) {
this . criteriaType = CriteriaType . GTE ;
@ -408,7 +414,7 @@ public class Criteria implements Predicate {
* Creates a criterion using a Regex
*
* @param pattern
* @return
* @return the criteria
* /
public Criteria regex ( Pattern pattern ) {
notNull ( pattern , "pattern can not be null" ) ;
@ -422,7 +428,7 @@ public class Criteria implements Predicate {
* to specify an array of possible matches .
*
* @param o the values to match against
* @return
* @return the criteria
* /
public Criteria in ( Object . . . o ) {
return in ( Arrays . asList ( o ) ) ;
@ -433,7 +439,7 @@ public class Criteria implements Predicate {
* to specify an array of possible matches .
*
* @param c the collection containing the values to match against
* @return
* @return the criteria
* /
public Criteria in ( Collection < ? > c ) {
notNull ( c , "collection can not be null" ) ;
@ -447,7 +453,7 @@ public class Criteria implements Predicate {
* which the specified field does not have any value in the specified array .
*
* @param o the values to match against
* @return
* @return the criteria
* /
public Criteria nin ( Object . . . o ) {
return nin ( Arrays . asList ( o ) ) ;
@ -458,7 +464,7 @@ public class Criteria implements Predicate {
* which the specified field does not have any value in the specified array .
*
* @param c the values to match against
* @return
* @return the criteria
* /
public Criteria nin ( Collection < ? > c ) {
notNull ( c , "collection can not be null" ) ;
@ -472,7 +478,7 @@ public class Criteria implements Predicate {
* in the specified array all values in the array must be matched .
*
* @param o
* @return
* @return the criteria
* /
public Criteria all ( Object . . . o ) {
return all ( Arrays . asList ( o ) ) ;
@ -483,7 +489,7 @@ public class Criteria implements Predicate {
* in the specified array all values in the array must be matched .
*
* @param c
* @return
* @return the criteria
* /
public Criteria all ( Collection < ? > c ) {
notNull ( c , "collection can not be null" ) ;
@ -501,7 +507,7 @@ public class Criteria implements Predicate {
* < / ol >
*
* @param size
* @return
* @return the criteria
* /
public Criteria size ( int size ) {
this . criteriaType = CriteriaType . SIZE ;
@ -514,7 +520,7 @@ public class Criteria implements Predicate {
* Check for existence ( or lack thereof ) of a field .
*
* @param b
* @return
* @return the criteria
* /
public Criteria exists ( boolean b ) {
this . criteriaType = CriteriaType . EXISTS ;
@ -526,7 +532,7 @@ public class Criteria implements Predicate {
* The $type operator matches values based on their Java type .
*
* @param t
* @return
* @return the criteria
* /
public Criteria type ( Class < ? > t ) {
notNull ( t , "type can not be null" ) ;
@ -538,7 +544,7 @@ public class Criteria implements Predicate {
/ * *
* The < code > notEmpty < / code > operator checks that an array or String is not empty .
*
* @return
* @return the criteria
* /
public Criteria notEmpty ( ) {
this . criteriaType = CriteriaType . NOT_EMPTY ;
@ -549,7 +555,8 @@ public class Criteria implements Predicate {
/ * *
* The < code > matches < / code > operator checks that an object matches the given predicate .
*
* @return
* @param p
* @return the criteria
* /
public Criteria matches ( Predicate p ) {
this . criteriaType = CriteriaType . MATCHES ;