### Question:
Condition { public boolean hasMissingComparisonValues() { if (comparisonOperator == null) { throw new InvalidConditionOperatorException("Comparison operator cannot be null"); } switch (comparisonOperator) { case EQUALS: case LESS_THAN_OR_EQUALS: case GREATER_THAN_OR_EQUALS: return !values.stream().anyMatch(value -> value != null && !value.isEmpty()); case NOT_NULL: case NULL: default: return false; } } Condition(final Operators comparisonOperator, final Set<String> values);  Condition(final Operators comparisonOperator, final String value);  Condition(final Operators comparisonOperator); @Override int hashCode(); @Override boolean equals(final Object obj); boolean hasMissingComparisonValues(); Operators getComparisonOperator(); Set<String> getValues(); @Override String toString();  }### Answer:
@Test public void shouldReturnHasMissingComparisonValues_withConditionWhichRequiresComparisonValuesAndNullOrEmptyValues() { final Set<Operators> operatorsWhichRequireNonNullOrEmptyValues = Sets.newSet(Operators.EQUALS, Operators.GREATER_THAN_OR_EQUALS, Operators.LESS_THAN_OR_EQUALS); final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet( operatorsWhichRequireNonNullOrEmptyValues); final String value = randomBoolean() ? null : ""; final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value); final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues(); assertTrue(hasMissingComparisonValues); }
@Test public void shouldReturnDoesNotHaveMissingComparisonValues_withConditionWhichRequiresComparisonValuesAndNonNullOrEmptyValues() { final Set<Operators> operatorsWhichRequireNonNullOrEmptyValues = Sets.newSet(Operators.EQUALS, Operators.GREATER_THAN_OR_EQUALS, Operators.LESS_THAN_OR_EQUALS); final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet( operatorsWhichRequireNonNullOrEmptyValues); final String value = randomString(10); final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value); final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues(); assertFalse(hasMissingComparisonValues); }
@Test public void shouldReturnDoesNotHaveMissingComparisonValues_withConditionWhichDoesNotRequireComparisonValuesAndNullOrEmptyValues() { final Set<Operators> operatorsWhichDoNotRequireNonNullOrEmptyValues = Sets.newSet(Operators.NOT_NULL, Operators.NULL); final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet( operatorsWhichDoNotRequireNonNullOrEmptyValues); final String value = randomBoolean() ? null : ""; final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value); final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues(); assertFalse(hasMissingComparisonValues); }
@Test public void shouldReturnDoesNotHaveMissingComparisonValues_withConditionWhichDoesNotRequireComparisonValuesAndNonNullOrEmptyValues() { final Set<Operators> operatorsWhichDoNotRequireNonNullOrEmptyValues = Sets.newSet(Operators.NOT_NULL, Operators.NULL); final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet( operatorsWhichDoNotRequireNonNullOrEmptyValues); final String value = randomString(); final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value); final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues(); assertFalse(hasMissingComparisonValues); }
@Test public void shouldNotReturnHasMissingComparisonValues_withNullOperator() { final Operators operators = null; final String value = randomString(); final Condition condition = new Condition(operators, value); InvalidConditionOperatorException thrownException = null; try { condition.hasMissingComparisonValues(); } catch (final InvalidConditionOperatorException e) { thrownException = e; } assertNotNull(thrownException); }