• 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.5
/DAL-java/src/main/java/com/github/leeonky/dal/extensions/MetaProperties.java
1
package com.github.leeonky.dal.extensions;
2

3
import com.github.leeonky.dal.DAL;
4
import com.github.leeonky.dal.ast.opt.DALOperator;
5
import com.github.leeonky.dal.runtime.*;
6
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
7
import com.github.leeonky.dal.runtime.checker.Checker;
8
import com.github.leeonky.dal.runtime.checker.CheckingContext;
9
import com.github.leeonky.interpreter.SyntaxException;
10
import com.github.leeonky.util.BeanClass;
11
import com.github.leeonky.util.NoSuchAccessorException;
12
import com.github.leeonky.util.Sneaky;
13

14
import java.util.Set;
15

16
import static com.github.leeonky.dal.runtime.DALException.extractException;
17
import static com.github.leeonky.dal.runtime.Operators.MATCH;
18
import static com.github.leeonky.dal.runtime.Order.BUILD_IN;
19

20
@Order(BUILD_IN)
21
public class MetaProperties implements Extension {
1✔
22
    private static Object size(MetaData<?> metaData) {
23
        return metaData.data().list().size();
1✔
24
    }
25

26
    private static Object throw_(MetaData<?> metaData) {
27
        try {
28
            metaData.data().value();
1✔
29
            throw new AssertionError("Expecting an error to be thrown, but nothing was thrown");
1✔
30
        } catch (Exception e) {
1✔
31
            return Sneaky.get(() -> extractException(e).orElseThrow(() -> e));
1✔
32
        }
33
    }
34

35
    private static Object object_(MetaData<?> metaData) {
36
        return metaData.data().value() == null ? null : new OriginalJavaObject(metaData.data());
1✔
37
    }
38

39
    private static Object keys(MetaData<?> metaData) {
40
        return metaData.data().fieldNames();
1✔
41
    }
42

43
    @Override
44
    public void extend(DAL dal) {
45
        dal.getRuntimeContextBuilder()
1✔
46
                .registerMetaProperty("size", MetaProperties::size)
1✔
47
                .registerMetaProperty("throw", MetaProperties::throw_)
1✔
48
                .registerMetaProperty("object", MetaProperties::object_)
1✔
49
                .registerMetaProperty("keys", MetaProperties::keys)
1✔
50
                .registerMetaProperty("should", MetaShould::new)
1✔
51
                .registerMetaProperty("this", (RuntimeDataHandler<MetaData<?>>) RuntimeData::data)
1✔
52
                .registerMetaProperty(MetaShould.class, "not", (metaData) -> metaData.data().value().negative())
1✔
53
                .registerMetaProperty("root", (RuntimeDataHandler<MetaData<?>>) metaData ->
1✔
54
                        metaData.runtimeContext().inputRoot())
1✔
55
        ;
56

57
        dal.getRuntimeContextBuilder().checkerSetForMatching()
1✔
58
                .register((expected, actual) -> actual.cast(MetaShould.PredicateMethod.class).map(predicateMethod -> new Checker() {
1✔
59
                    private MetaShould.PredicateMethod resolved;
60

61
                    @Override
62
                    public boolean failed(CheckingContext checkingContext) {
63
                        return !(resolved = (MetaShould.PredicateMethod) predicateMethod.getValue(expected.value())).should();
1✔
64
                    }
65

66
                    @Override
67
                    public String message(CheckingContext checkingContext) {
68
                        return resolved.errorMessage();
1✔
69
                    }
70
                }))
71
                .register((expected, actual) -> actual.cast(CurryingMethod.class).map(curryingMethod -> new Checker() {
1✔
72
                    @Override
73
                    public Data<?> verify(Data<?> expected, Data<?> actual, DALRuntimeContext context) {
74
                        return actual.property(expected.value());
1✔
75
                    }
76
                }))
77
        ;
78

79
        dal.getRuntimeContextBuilder().checkerSetForEqualing()
1✔
80
                .register((expected, actual) -> actual.cast(MetaShould.PredicateMethod.class).map(predicateMethod -> new Checker() {
1✔
81
                    @Override
82
                    public boolean failed(CheckingContext checkingContext) {
83
                        throw ExpressionException.exception(expression -> new SyntaxException("Should use `:` in ::should verification",
1✔
84
                                expression.operator().getPosition()));
1✔
85
                    }
86
                }));
87

88
        dal.getRuntimeContextBuilder().registerOperator(MATCH, new Operation<CurryingMethod, ExpectationFactory>() {
1✔
89

90
            @Override
91
            public boolean match(Data<?> v1, DALOperator operator, Data<?> v2, DALRuntimeContext context) {
92
                return v1.instanceOf(CurryingMethod.class) && v2.instanceOf(ExpectationFactory.class);
1✔
93
            }
94

95
            @Override
96
            public Data<?> operateData(Data<CurryingMethod> v1, DALOperator operator, Data<ExpectationFactory> v2, DALRuntimeContext context) {
97
                return v2.value().create(operator, v1).matches();
1✔
98
            }
99
        });
100
    }
1✔
101

102
    static class OriginalJavaObject implements ProxyObject {
103
        private final Data<?> data;
104

105
        public OriginalJavaObject(Data<?> data) {
1✔
106
            this.data = data;
1✔
107
        }
1✔
108

109
        @Override
110
        public Object getValue(Object property) {
111
            try {
112
                Object instance = data.value();
1✔
113
                return BeanClass.createFrom(instance).getPropertyValue(instance, property.toString());
1✔
114
            } catch (NoSuchAccessorException ignore) {
1✔
115
                return data.property(property).value();
1✔
116
            }
117
        }
118

119
        @Override
120
        public Set<?> getPropertyNames() {
UNCOV
121
            return BeanClass.createFrom(data.value()).getPropertyReaders().keySet();
×
122
        }
123
    }
124
}
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