LogicalConditions { public static <T extends UserContext> SendCondition<T> and(final SendCondition<T> first, final SendCondition<T> second) { return new SendCondition<T>() { @Override public boolean isApplicable(T userContext) { return first.isApplicable(userContext) && second.isApplicable(userContext); } }; } private  LogicalConditions(); static SendCondition<T> and(final SendCondition<T> first, final SendCondition<T> second); static SendCondition<T> and(final SendCondition<T>... conditions); static SendCondition<T> or(final SendCondition<T> first, final SendCondition<T> second); static SendCondition<T> or(final SendCondition<T>... conditions); static SendCondition<T> not(final SendCondition<T> condition);  }
@Test public void testAndConditionTwoConditionsAccepting() throws Exception { SendCondition<UserContext> acceptingCondition1 = createAcceptingCondition(); SendCondition<UserContext> acceptingCondition2 = createAcceptingCondition(); SendCondition<UserContext> andCondition = LogicalConditions.and(acceptingCondition1, acceptingCondition2); UserContext user = createUserContextObject(); boolean isApplicable = andCondition.isApplicable(user); assertTrue(isApplicable); }
@Test public void testAndConditionOneConditionAccepting() throws Exception { SendCondition<UserContext> acceptingCondition = createAcceptingCondition(); SendCondition<UserContext> refusingCondition = createRefusingCondition(); SendCondition<UserContext> andCondition = LogicalConditions.and(acceptingCondition, refusingCondition); UserContext user = createUserContextObject(); boolean isApplicable = andCondition.isApplicable(user); assertFalse(isApplicable); }
@Test public void testAndConditionThreeConditionsAccepting() throws Exception { SendCondition<UserContext> acceptingCondition1 = createAcceptingCondition(); SendCondition<UserContext> acceptingCondition2 = createAcceptingCondition(); SendCondition<UserContext> acceptingCondition3 = createAcceptingCondition(); SendCondition<UserContext> andCondition = LogicalConditions.and(acceptingCondition1, acceptingCondition2, acceptingCondition3); UserContext user = createUserContextObject(); boolean isApplicable = andCondition.isApplicable(user); assertTrue(isApplicable); }