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

leeonky / test-charm-java / 242

01 May 2025 09:52AM UTC coverage: 74.278% (+0.05%) from 74.224%
242

push

circleci

leeonky
Update version

8077 of 10874 relevant lines covered (74.28%)

0.74 hits per line

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

97.44
/DAL-java/src/main/java/com/github/leeonky/dal/extensions/Types.java
1
package com.github.leeonky.dal.extensions;
2

3
import com.github.leeonky.dal.DAL;
4
import com.github.leeonky.dal.runtime.*;
5
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
6
import com.github.leeonky.dal.runtime.checker.Checker;
7
import com.github.leeonky.dal.runtime.checker.CheckerSet;
8
import com.github.leeonky.util.Sneaky;
9

10
import java.util.Collection;
11
import java.util.Map;
12
import java.util.Optional;
13
import java.util.Set;
14
import java.util.function.Function;
15
import java.util.stream.Stream;
16

17
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOp2;
18
import static com.github.leeonky.dal.runtime.ExpressionException.opt1;
19
import static com.github.leeonky.dal.runtime.Order.BUILD_IN;
20
import static java.util.Optional.of;
21

22
@Order(BUILD_IN)
23
public class Types implements Extension {
1✔
24

25
    @Override
26
    public void extend(DAL dal) {
27
        RuntimeContextBuilder builder = dal.getRuntimeContextBuilder();
1✔
28
        builder.registerPropertyAccessor(Map.class, new MapPropertyAccessor())
1✔
29
                .registerPropertyAccessor(AutoMappingList.class, new AutoMappingListPropertyAccessor())
1✔
30
                .registerDALCollectionFactory(Iterable.class, IterableDALCollection::new)
1✔
31
                .registerDALCollectionFactory(Collection.class, CollectionDALCollection::new)
1✔
32
                .registerDALCollectionFactory(Stream.class, (stream) ->
1✔
33
                        new IterableDALCollection<Object>(stream::iterator))
1✔
34
                .registerDALCollectionFactory(DALCollection.class, instance -> instance)
1✔
35
                .registerDataRemark(DataRemarkParameterAcceptor.class, remarkData ->
1✔
36
                        remarkData.data().value().apply(remarkData.remark()))
×
37
                .registerPropertyAccessor(ProxyObject.class, new PropertyAccessor<ProxyObject>() {
1✔
38
                    @Override
39
                    public Object getValue(ProxyObject proxyObject, Object property) {
40
                        return proxyObject.getValue(property);
1✔
41
                    }
42

43
                    @Override
44
                    public Set<?> getPropertyNames(ProxyObject proxyObject) {
45
                        return proxyObject.getPropertyNames();
1✔
46
                    }
47

48
                    @Override
49
                    public boolean isNull(ProxyObject proxyObject) {
50
                        return proxyObject.isNull();
1✔
51
                    }
52
                })
53
                .registerReturnHook(d -> d.cast(ReturnHook.class).ifPresent(ReturnHook::onReturn))
1✔
54
                .registerDALCollectionFactory(AdaptiveList.class, AdaptiveList::list)
1✔
55
                .registerPropertyAccessor(AdaptiveList.class, new PropertyAccessor<AdaptiveList<?>>() {
1✔
56

57
                    @Override
58
                    public Data<?> getData(Data<AdaptiveList<?>> data, Object property, DALRuntimeContext context) {
59
                        return adaptiveListOf(data, d -> d.map(AdaptiveList::soloList).property(0).property(property));
1✔
60
                    }
61

62
                    @Override
63
                    public Set<?> getPropertyNames(Data<AdaptiveList<?>> data) {
64
                        return adaptiveListOf(data, d -> d.map(AdaptiveList::soloList).property(0).fieldNames());
1✔
65
                    }
66
                })
67
                .registerMetaPropertyPattern(AdaptiveList.class, ".*",
1✔
68
                        (RuntimeDataHandler<MetaData<AdaptiveList>>) metaData -> {
69
                            if (metaData.name().equals("size"))
1✔
70
                                return metaData.delegate(d -> d.map(AdaptiveList::list));
1✔
71
                            else
72
                                return metaData.delegate(d -> adaptiveListOf(Sneaky.cast(d),
1✔
73
                                        data -> data.map(AdaptiveList::soloList).property(0)));
1✔
74
                        })
75
        ;
76

77
        verifySingle(builder.checkerSetForEqualing());
1✔
78
        verifySingle(builder.checkerSetForMatching());
1✔
79
    }
1✔
80

81
    private void verifySingle(CheckerSet checkerSet) {
82
        checkerSet.register((expected, actual) -> {
1✔
83
            if (actual.instanceOf(AdaptiveList.class)) {
1✔
84
                Data<Object> single = opt1(() -> actual.map(t -> ((AdaptiveList<?>) t).single()));
1✔
85
                Checker checkerOfElement = checkerSet.fetch(expected, single);
1✔
86
                return of(new Checker() {
1✔
87
                    @Override
88
                    public Data<?> verify(Data<?> expected1, Data<?> actual1, DALRuntimeContext context) {
89
                        return checkerOfElement.verify(expected1, single, context);
1✔
90
                    }
91
                });
92
            }
93
            return Optional.empty();
1✔
94
        });
95
    }
1✔
96

97
    private <T> T adaptiveListOf(Data<AdaptiveList<?>> data, Function<Data<AdaptiveList<?>>, T> function) {
98
        try {
99
            return function.apply(data);
1✔
100
        } catch (InvalidAdaptiveListException e) {
1✔
101
            throw illegalOp2("Expected list can only have one element, but is: " + data.dump());
1✔
102
        }
103
    }
104
}
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