1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package gov.nist.secauto.metaschema.core.metapath;
28
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30
31 import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem;
32 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
33
34 import org.jmock.Expectations;
35 import org.jmock.Mockery;
36 import org.junit.jupiter.params.ParameterizedTest;
37 import org.junit.jupiter.params.provider.Arguments;
38 import org.junit.jupiter.params.provider.MethodSource;
39
40 import java.util.stream.Stream;
41
42 class OrTest
43 extends ExpressionTestBase {
44
45 private static Stream<Arguments> testOr() {
46 return Stream.of(
47 Arguments.of(IBooleanItem.TRUE, IBooleanItem.TRUE, IBooleanItem.TRUE),
48 Arguments.of(IBooleanItem.TRUE, IBooleanItem.FALSE, IBooleanItem.TRUE),
49 Arguments.of(IBooleanItem.FALSE, IBooleanItem.TRUE, IBooleanItem.TRUE),
50 Arguments.of(IBooleanItem.FALSE, IBooleanItem.FALSE, IBooleanItem.FALSE));
51 }
52
53 @ParameterizedTest
54 @MethodSource
55 void testOr(IBooleanItem bool1, IBooleanItem bool2, IBooleanItem expectedResult) {
56 DynamicContext dynamicContext = newDynamicContext();
57 Mockery context = getContext();
58
59 ISequence<?> focus = ISequence.empty();
60
61 IExpression exp1 = context.mock(IExpression.class, "exp1");
62 IExpression exp2 = context.mock(IExpression.class, "exp2");
63
64 context.checking(new Expectations() {
65 {
66 atMost(1).of(exp1).accept(dynamicContext, focus);
67 will(returnValue(ISequence.of(bool1)));
68 atMost(1).of(exp2).accept(dynamicContext, focus);
69 will(returnValue(ISequence.of(bool2)));
70 }
71 });
72
73 Or expr = new Or(exp1, exp2);
74
75 ISequence<?> result = expr.accept(dynamicContext, focus);
76 assertEquals(ISequence.of(expectedResult), result, "Sequence does not match");
77
78 result = MetapathExpression.compile(ObjectUtils.notNull(
79 new StringBuilder()
80 .append(bool1.toBoolean() ? "true()" : "false()")
81 .append(" or ")
82 .append(bool2.toBoolean() ? "true()" : "false()")
83 .toString()))
84 .evaluate();
85 assertEquals(ISequence.of(expectedResult), result, "Sequence does not match");
86 }
87 }