SequenceDescriptorEvaluator { public boolean evaluate(final WilmaHttpRequest request, final SequenceDescriptor sequenceDescriptor) { boolean result = false; result = checkConditions(request, sequenceDescriptor, result); if (!result) { result = checkDialogDescriptors(request, sequenceDescriptor, result); } return result; }  boolean evaluate(final WilmaHttpRequest request, final SequenceDescriptor sequenceDescriptor);  }
@Test public void testEvaluateWhenThereIsNotAnyConditionAndDialogDescriptor() { given(sequenceDescriptor.getConditionDescriptors()).willReturn(new ArrayList<ConditionDescriptor>()); given(sequenceDescriptor.getDialogDescriptors()).willReturn(new ArrayList<DialogDescriptor>()); boolean result = underTest.evaluate(request, sequenceDescriptor); Assert.assertFalse(result); }
@Test public void testEvaluateWhenAConditionIsTrue() { given(dialogDescriptor.getConditionDescriptor()).willReturn(conditionDescriptor); given(conditionDescriptor.getCondition()).willReturn(condition); given(conditionEvaluator.evaluate(condition, clonedRequest)).willReturn(true); List<ConditionDescriptor> cds = new ArrayList<>(); cds.add(conditionDescriptor); given(sequenceDescriptor.getConditionDescriptors()).willReturn(cds); List<DialogDescriptor> dds = new ArrayList<>(); dds.add(dialogDescriptor); given(sequenceDescriptor.getDialogDescriptors()).willReturn(dds); boolean result = underTest.evaluate(request, sequenceDescriptor); Assert.assertTrue(result); }
@Test public void testEvaluateWhenOccurredAnExceptionInConditionEvaluation() { Exception e = new RuntimeException(); given(sequenceDescriptor.getName()).willReturn("test"); given(dialogDescriptor.getConditionDescriptor()).willReturn(conditionDescriptor); given(conditionDescriptor.getCondition()).willReturn(condition); given(conditionEvaluator.evaluate(condition, clonedRequest)).willThrow(e); List<ConditionDescriptor> cds = new ArrayList<>(); cds.add(conditionDescriptor); given(sequenceDescriptor.getConditionDescriptors()).willReturn(cds); given(sequenceDescriptor.getDialogDescriptors()).willReturn(new ArrayList<DialogDescriptor>()); boolean result = underTest.evaluate(request, sequenceDescriptor); Assert.assertFalse(result); }
@Test public void testEvaluateWhenADialogDescriptorIsTrue() { given(dialogDescriptor.getConditionDescriptor()).willReturn(conditionDescriptor); given(conditionDescriptor.getCondition()).willReturn(condition); given(conditionEvaluator.evaluate(condition, clonedRequest)).willReturn(false).willReturn(true); List<ConditionDescriptor> cds = new ArrayList<>(); cds.add(conditionDescriptor); given(sequenceDescriptor.getConditionDescriptors()).willReturn(cds); List<DialogDescriptor> dds = new ArrayList<>(); dds.add(dialogDescriptor); given(sequenceDescriptor.getDialogDescriptors()).willReturn(dds); boolean result = underTest.evaluate(request, sequenceDescriptor); Assert.assertTrue(result); }
@Test public void testEvaluateWhenDialogDescriptorIsNotEnabled() { given(dialogDescriptorService.isEnabled(dialogDescriptor)).willReturn(false); given(dialogDescriptor.getConditionDescriptor()).willReturn(conditionDescriptor); given(conditionDescriptor.getCondition()).willReturn(condition); given(conditionEvaluator.evaluate(condition, clonedRequest)).willReturn(false).willReturn(true); List<ConditionDescriptor> cds = new ArrayList<>(); cds.add(conditionDescriptor); given(sequenceDescriptor.getConditionDescriptors()).willReturn(cds); List<DialogDescriptor> dds = new ArrayList<>(); dds.add(dialogDescriptor); given(sequenceDescriptor.getDialogDescriptors()).willReturn(dds); boolean result = underTest.evaluate(request, sequenceDescriptor); Assert.assertFalse(result); }