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

leeonky / test-charm-java / 290

08 Sep 2025 03:25PM UTC coverage: 74.312% (-0.003%) from 74.315%
290

push

circleci

leeonky
Introduce PropertyWriterDecorator

10 of 25 new or added lines in 6 files covered. (40.0%)

20 existing lines in 10 files now uncovered.

8155 of 10974 relevant lines covered (74.31%)

0.74 hits per line

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

97.56
/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.Data;
5
import com.github.leeonky.dal.runtime.ExpectationFactory;
6
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
7
import com.github.leeonky.interpreter.SyntaxException;
8

9
import java.util.ArrayList;
10
import java.util.LinkedHashSet;
11
import java.util.List;
12
import java.util.Set;
13
import java.util.stream.Stream;
14

15
import static com.github.leeonky.dal.runtime.ExpressionException.exception;
16
import static com.github.leeonky.dal.runtime.ExpressionException.opt1;
17
import static java.lang.String.format;
18
import static java.util.stream.Collectors.joining;
19

20
public class ObjectScopeNode extends DALNode {
21
    private final List<DALNode> verificationExpressions = new ArrayList<>();
1✔
22
    private final boolean isObjectWildcard;
23

24
    public ObjectScopeNode(List<DALNode> expressions) {
1✔
25
        verificationExpressions.addAll(expressions);
1✔
26
        isObjectWildcard = false;
1✔
27
    }
1✔
28

29
    public ObjectScopeNode(DALNode ignore) {
1✔
30
        isObjectWildcard = true;
1✔
31
    }
1✔
32

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

39
    @Override
40
    protected ExpectationFactory toVerify(DALRuntimeContext context) {
41
        return (operator, actual) -> new ExpectationFactory.Expectation() {
1✔
42
            @Override
43
            public Data<?> matches() {
44
                if (verificationExpressions.isEmpty() && !isObjectWildcard)
1✔
45
                    throw new SyntaxException("Should use `{...}` to verify any non null object or `=` before {}", getPositionBegin());
1✔
46
                if (isObjectWildcard && opt1(actual::isNull))
1✔
47
                    throw new AssertionFailure("Expected value to be not null, but it was null", getOperandPosition());
1✔
48
                return actual.execute(() -> {
1✔
49
                    Data<?> result = context.data(null);
1✔
50
                    for (DALNode expression : verificationExpressions)
1✔
51
                        result = expression.evaluateData(context);
1✔
52
                    return result;
1✔
53
                });
54
            }
55

56
            @Override
57
            public Data<?> equalTo() {
58
                if ((isObjectWildcard || verificationExpressions.isEmpty()) && opt1(actual::isNull))
1✔
59
                    throw new AssertionFailure("Expected value to be not null, but it was null", getOperandPosition());
1✔
60
                Data<?> execute = actual.execute(() -> {
1✔
61
                    Data<?> result = context.data(null);
1✔
62
                    for (DALNode expression : verificationExpressions)
1✔
63
                        result = expression.evaluateData(context);
1✔
64
                    return result;
1✔
65
                });
66
                if (!opt1(actual::isNull)) {
1✔
67
                    Set<Object> dataFields = collectUnexpectedFields(actual, context);
1✔
68
                    if (!dataFields.isEmpty())
1✔
69
                        throw exception(expression -> {
1✔
70
                            String element = expression.left().inspect();
1✔
71
                            return new AssertionFailure(format("Unexpected fields %s%s",
1✔
72
                                    dataFields.stream().map(s -> s instanceof String ? format("`%s`", s) : s.toString())
1✔
73
                                            .collect(joining(", ")), element.isEmpty() ? "" : " in " + element), expression.operator().getPosition());
1✔
74
                        });
75
                }
76
                return execute;
1✔
77
            }
78

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

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

92
    @Override
93
    public Stream<Object> collectFields(Data<?> data) {
94
        return verificationExpressions.stream().flatMap(expression -> expression.collectFields(data));
1✔
95
    }
96
}
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