@Test public void threeElements() { AndExpression andExpression = new AndExpression(expr1, expr2, expr3); assertThat(andExpression.getNumberOfChildExpressions(), is(3)); } }
@Test public void empty() { AndExpression andExpression = new AndExpression(); assertThat(andExpression.getOperands(), hasSize(0)); }
@Test public void canAddIfEmpty() { AndExpression andExpression = new AndExpression(); assertThat(andExpression.canAddOperand(), is(true)); }
@Test public void noOperand() { boolean evaluationResult = new AndExpression().evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void canAddWithExistingElements() { AndExpression andExpression = new AndExpression(expr1, expr2, expr3); assertThat(andExpression.canAddOperand(), is(true)); } }
@Test public void empty() { AndExpression andExpression = new AndExpression(); assertThat(andExpression.getNumberOfChildExpressions(), is(0)); }
/** * Creates an {@link AbstractExpression} for the given {@link BooleanExpressionType}. * * @param type * {@link BooleanExpressionType} determining the specific {@link AbstractExpression}. * @return an {@link AbstractExpression}. */ private static AbstractExpression createBooleanExpression(BooleanExpressionType type) { switch (type) { case AND: return new AndExpression(); case OR: return new OrExpression(); case NOT: return new NotExpression(); case BOOLEAN: return new BooleanExpression(false); default: throw new RuntimeException("Unsupported type!"); } }
@Test public void oneOperandTrue() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(true); AndExpression andExpression = new AndExpression(expr1); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void withElements() { AndExpression andExpression = new AndExpression(expr1, expr2, expr3); assertThat(andExpression.getOperands(), hasSize(3)); assertThat(andExpression.getOperands(), contains((AbstractExpression) expr1, expr2, expr3)); } }
@Test public void oneOperandFalse() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(false); AndExpression andExpression = new AndExpression(expr1); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(false)); }
@Test public void removeOne() { AndExpression andExpression = new AndExpression(expr1, expr2, expr3); andExpression.removeOperand(expr2); assertThat(andExpression.getOperands(), hasSize(2)); }
@Test public void removeNotExistent() { AndExpression andExpression = new AndExpression(expr1, expr3); andExpression.removeOperand(expr2); assertThat(andExpression.getOperands(), hasSize(2)); }
@Test public void twoOperandsFalse() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr2.evaluate(invocation, cachedDataService)).thenReturn(false); AndExpression andExpression = new AndExpression(expr1, expr2); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(false)); }
@Test public void twoOperandsTrue() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr2.evaluate(invocation, cachedDataService)).thenReturn(true); AndExpression andExpression = new AndExpression(expr1, expr2); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void threeOperandsTrue() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr2.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr3.evaluate(invocation, cachedDataService)).thenReturn(true); AndExpression andExpression = new AndExpression(expr1, expr2, expr3); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void threeOperandsFalse() { when(expr1.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr2.evaluate(invocation, cachedDataService)).thenReturn(true); when(expr3.evaluate(invocation, cachedDataService)).thenReturn(false); AndExpression andExpression = new AndExpression(expr1, expr2, expr3); boolean evaluationResult = andExpression.evaluate(invocation, cachedDataService); assertThat(evaluationResult, is(false)); } }
@Test public void add() { AndExpression andExpression = new AndExpression(); andExpression.addOperand(new OrExpression()); assertThat(andExpression.getOperands(), hasSize(1)); }
@Test public void removeTwice() { AndExpression andExpression = new AndExpression(expr1, expr2, expr3); andExpression.removeOperand(expr2); andExpression.removeOperand(expr2); assertThat(andExpression.getOperands(), hasSize(2)); } }
@Test public void addDuplicate() { AndExpression andExpression = new AndExpression(); OrExpression operand = new OrExpression(); andExpression.addOperand(operand); andExpression.addOperand(operand); assertThat(andExpression.getOperands(), hasSize(1)); } }
@Test public void addTwo() { AndExpression andExpression = new AndExpression(); andExpression.addOperand(new OrExpression()); andExpression.addOperand(new OrExpression()); assertThat(andExpression.getOperands(), hasSize(2)); }