ttt
ttt

Reputation: 4004

How to test a Google Guava Predicate factory kind of class

I have a class called XxxPredicateFactory which return a single predicate or predicate combination. Something like this:

Public class XxxPredicateFactory {

     public Predicate<Abc> create() {
          if (this) {
              return new HelloPredicate<Abc>();
          }
          else if (that) {
              return new WorldPredicate<Abc>();
          }
          else {
               return Predicates.or(new HelloPredicate<Abc>(), new WorldPredicate<Abc>());
          }
     }

}

For the if and else if, it seems easy to test, but for the else part I am not quite sure how can I test this? How can I capture this situation?

Upvotes: 0

Views: 168

Answers (1)

ColinD
ColinD

Reputation: 110046

Can you not just test that the returned predicate returns true for both things that HelloPredicate should return true for and things that WorldPredicate should return true for?

Upvotes: 1

Related Questions