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

leeonky / test-charm-java / 323

30 Sep 2025 05:15PM UTC coverage: 74.637% (+0.1%) from 74.512%
323

push

circleci

leeonky
Use descendantForRead in consistent provider

16 of 17 new or added lines in 4 files covered. (94.12%)

29 existing lines in 7 files now uncovered.

8531 of 11430 relevant lines covered (74.64%)

0.75 hits per line

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

90.91
/jfactory/src/main/java/com/github/leeonky/jfactory/DefaultListConsistency.java
1
package com.github.leeonky.jfactory;
2

3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.function.Function;
6

7
import static com.github.leeonky.jfactory.DefaultConsistency.LINK_COMPOSER;
8
import static com.github.leeonky.jfactory.DefaultConsistency.LINK_DECOMPOSER;
9
import static com.github.leeonky.jfactory.PropertyChain.propertyChain;
10
import static java.util.Arrays.asList;
11
import static java.util.Collections.singletonList;
12

13
class DefaultListConsistency<T> implements ListConsistency<T> {
14
    private final PropertyChain listProperty;
15
    private final Consistency<T> consistency;
16
    private final List<ListConsistencyItem<T>> items = new ArrayList<>();
1✔
17

18
    DefaultListConsistency(String listProperty, Consistency<T> consistency) {
1✔
19
        this.listProperty = propertyChain(listProperty);
1✔
20
        this.consistency = consistency;
1✔
21
    }
1✔
22

23
    @Override
24
    @SuppressWarnings("unchecked")
25
    public ListConsistency<T> direct(String property) {
26
        return property(property).read((Function<Object, T>) LINK_COMPOSER).write((Function<T, Object>) LINK_DECOMPOSER);
1✔
27
    }
28

29
    @Override
30
    public <P> ListConsistency.LC1<T, P> property(String property) {
31
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(singletonList(property));
1✔
32
        items.add(listConsistencyItem);
1✔
33
        return new DefaultListConsistency.LC1<>(this, listConsistencyItem);
1✔
34
    }
35

36
    @Override
37
    public <P1, P2> ListConsistency.LC2<T, P1, P2> properties(String property1, String property2) {
38
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2));
1✔
39
        items.add(listConsistencyItem);
1✔
40
        return new DefaultListConsistency.LC2<>(this, listConsistencyItem);
1✔
41
    }
42

43
    @Override
44
    public <P1, P2, P3> LC3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
45
        ListConsistencyItem<T> listConsistencyItem = new ListConsistencyItem<>(asList(property1, property2, property3));
1✔
46
        items.add(listConsistencyItem);
1✔
47
        return new LC3<>(this, listConsistencyItem);
1✔
48
    }
49

50
    private String combine(int index, String property) {
51
        return listProperty.toString() + String.format("[%d].", index) + property;
1✔
52
    }
53

54
    void resolveToItems(ObjectProducer<?> producer) {
55
        Producer<?> descendant = producer.descendantForUpdate(listProperty);
1✔
56
        if (descendant instanceof CollectionProducer) {
1✔
57
            CollectionProducer<?, ?> collectionProducer = (CollectionProducer<?, ?>) descendant;
1✔
58
            int count = collectionProducer.childrenCount();
1✔
59
            for (int i = 0; i < count; i++) {
1✔
60
                int index = i;
1✔
61
                for (ListConsistencyItem<T> listConsistencyItem : items) {
1✔
62
                    consistency.properties(listConsistencyItem.property.stream().map(p -> combine(index, p)).toArray(String[]::new))
1✔
63
                            .read(listConsistencyItem.composer)
1✔
64
                            .write(listConsistencyItem.decomposer);
1✔
65
                }
1✔
66
            }
67
        } else
1✔
UNCOV
68
            throw new IllegalStateException();
×
69
    }
1✔
70
}
71

72
class DecorateListConsistency<T> implements ListConsistency<T> {
73
    private final ListConsistency<T> delegate;
74

75
    public DecorateListConsistency(ListConsistency<T> delegate) {
1✔
76
        this.delegate = delegate;
1✔
77
    }
1✔
78

79
    @Override
80
    public ListConsistency<T> direct(String property) {
81
        return delegate.direct(property);
1✔
82
    }
83

84
    @Override
85
    public <P> ListConsistency.LC1<T, P> property(String property) {
UNCOV
86
        return delegate.property(property);
×
87
    }
88

89
    @Override
90
    public <P1, P2> ListConsistency.LC2<T, P1, P2> properties(String property1, String property2) {
UNCOV
91
        return delegate.properties(property1, property2);
×
92
    }
93

94
    @Override
95
    public <P1, P2, P3> LC3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
UNCOV
96
        return delegate.properties(property1, property2, property3);
×
97
    }
98
}
99

100
class MultiPropertyListConsistency<T, C extends MultiPropertyListConsistency<T, C>> extends DecorateListConsistency<T> {
101
    final ListConsistencyItem<T> last;
102

103
    MultiPropertyListConsistency(ListConsistency<T> delegate, ListConsistencyItem<T> last) {
104
        super(delegate);
1✔
105
        this.last = last;
1✔
106
    }
1✔
107

108
    @SuppressWarnings("unchecked")
109
    public C read(Function<Object[], T> composer) {
110
        last.setComposer(new ComposerWrapper<>(composer, composer));
1✔
111
        return (C) this;
1✔
112
    }
113

114
    @SuppressWarnings("unchecked")
115
    public C write(Function<T, Object[]> decomposer) {
116
        last.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
117
        return (C) this;
1✔
118
    }
119
}
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