• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 156

20 Mar 2025 01:53PM UTC coverage: 74.243% (-0.2%) from 74.475%
156

push

circleci

leeonky
Refactor

14 of 15 new or added lines in 12 files covered. (93.33%)

126 existing lines in 29 files now uncovered.

7947 of 10704 relevant lines covered (74.24%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.62
/DAL-java/src/main/java/com/github/leeonky/dal/ast/node/ObjectScopeNode.java
1
package com.github.leeonky.dal.ast.node;
2

3
import com.github.leeonky.dal.runtime.AssertionFailure;
4
import com.github.leeonky.dal.runtime.CurryingMethod;
5
import com.github.leeonky.dal.runtime.Data;
6
import com.github.leeonky.dal.runtime.Data.Resolved;
7
import com.github.leeonky.dal.runtime.ExpectationFactory;
8
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
9
import com.github.leeonky.interpreter.SyntaxException;
10

11
import java.util.ArrayList;
12
import java.util.LinkedHashSet;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.stream.Stream;
16

17
import static com.github.leeonky.dal.runtime.Data.ResolvedMethods.cast;
18
import static com.github.leeonky.dal.runtime.ExpressionException.exception;
19
import static com.github.leeonky.dal.runtime.ExpressionException.opt1;
20
import static java.lang.String.format;
21
import static java.util.stream.Collectors.joining;
22

23
public class ObjectScopeNode extends DALNode {
24
    private final List<DALNode> verificationExpressions = new ArrayList<>();
1✔
25
    private final boolean isObjectWildcard;
26

27
    public ObjectScopeNode(List<DALNode> expressions) {
1✔
28
        verificationExpressions.addAll(expressions);
1✔
29
        isObjectWildcard = false;
1✔
30
    }
1✔
31

32
    public ObjectScopeNode(DALNode ignore) {
1✔
33
        isObjectWildcard = true;
1✔
34
    }
1✔
35

36
    @Override
37
    public String inspect() {
38
        return format("{%s}", isObjectWildcard ? "..." : verificationExpressions.stream().map(DALNode::inspect)
1✔
39
                .collect(joining(", ")));
1✔
40
    }
41

42
    @Override
43
    protected ExpectationFactory toVerify(DALRuntimeContext context) {
44
        return (operator, actual) -> new ExpectationFactory.Expectation() {
1✔
45
            @Override
46
            public Data matches() {
47
                if (verificationExpressions.isEmpty() && !isObjectWildcard)
1✔
48
                    throw new SyntaxException("Should use `{...}` to verify any non null object", getPositionBegin());
1✔
49
                if (opt1(actual.get(Resolved::isNull)))
1✔
50
                    throw new AssertionFailure("The input value is null", getOperandPosition());
1✔
51
                return actual.execute(() -> {
1✔
52
                    Data result = context.wrap(() -> null);
1✔
53
                    for (DALNode expression : verificationExpressions)
1✔
54
                        result = expression.evaluateData(context).resolve();
1✔
55
                    return result;
1✔
56
                });
57
            }
58

59
            @Override
60
            public Data equalTo() {
61
                if (opt1(actual.get(Resolved::isNull)))
1✔
62
                    throw new AssertionFailure("The input value is null", getOperandPosition());
1✔
63
                Data execute = actual.execute(() -> {
1✔
64
                    Data result = context.wrap(() -> null);
1✔
65
                    for (DALNode expression : verificationExpressions)
1✔
66
                        result = expression.evaluateData(context).resolve();
1✔
67
                    return result;
1✔
68
                });
69
                Set<Object> dataFields = collectUnexpectedFields(actual, context);
1✔
70
                if (!dataFields.isEmpty())
1✔
71
                    throw exception(expression -> {
1✔
72
                        String element = expression.left().inspect();
1✔
73
                        return new AssertionFailure(format("Unexpected fields %s%s",
1✔
74
                                dataFields.stream().map(s -> s instanceof String ? format("`%s`", s) : s.toString())
1✔
75
                                        .collect(joining(", ")), element.isEmpty() ? "" : " in " + element), expression.operator().getPosition());
1✔
76
                    });
77
                return execute;
1✔
78
            }
79

80
            @Override
81
            public ExpectationFactory.Type type() {
UNCOV
82
                return ExpectationFactory.Type.OBJECT;
×
83
            }
84
        };
85
    }
86

87
    private Set<Object> collectUnexpectedFields(Data data, DALRuntimeContext context) {
88
        return new LinkedHashSet<Object>(data.resolved().fieldNames()) {{
1✔
89
            Stream.concat(collectFields(data), context.collectPartialProperties(data).stream())
1✔
90
                    .map(obj -> convertFiled(data, obj)).forEach(this::remove);
1✔
91
        }};
1✔
92
    }
93

94
    private Object convertFiled(Data data, Object obj) {
95
        return data.probe(cast(CurryingMethod.class)).map(curryingMethod -> curryingMethod.convertToArgType(obj)).orElse(obj);
1✔
96
    }
97

98
    @Override
99
    public Stream<Object> collectFields(Data data) {
100
        return verificationExpressions.stream().flatMap(expression -> expression.collectFields(data));
1✔
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc