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

leeonky / test-charm-java / 284

03 Sep 2025 03:51PM UTC coverage: 74.307% (-0.01%) from 74.317%
284

push

circleci

leeonky
Refator

30 of 30 new or added lines in 2 files covered. (100.0%)

9 existing lines in 3 files now uncovered.

8098 of 10898 relevant lines covered (74.31%)

0.74 hits per line

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

97.37
/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
        ;
54

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

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

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

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

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

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

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

100
    static class OriginalJavaObject implements ProxyObject {
101
        private final Data<?> data;
102

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

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

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