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

leeonky / test-charm-java / 296

15 Sep 2025 02:01PM UTC coverage: 74.593% (+0.4%) from 74.22%
296

push

circleci

leeonky
checking during consistency merge

89 of 94 new or added lines in 6 files covered. (94.68%)

11 existing lines in 6 files now uncovered.

8435 of 11308 relevant lines covered (74.59%)

0.75 hits per line

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

85.96
/jfactory/src/main/java/com/github/leeonky/jfactory/Consistency.java
1
package com.github.leeonky.jfactory;
2

3
import com.github.leeonky.util.BeanClass;
4

5
import java.util.Objects;
6
import java.util.function.BiFunction;
7
import java.util.function.Function;
8

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
public interface Consistency<T> {
14
    Function<Object[], ?> LINK_COMPOSER = objs -> objs[0];
1✔
15
    Function<?, Object[]> LINK_DECOMPOSER = t -> new Object[]{t};
1✔
16

17
    Consistency<T> link(ConsistencyItem<T> item);
18

19
    void apply(Producer<?> producer);
20

21
    BeanClass<T> type();
22

23
    @SuppressWarnings("unchecked")
24
    default Consistency<T> direct(String property) {
25
        ConsistencyItem<T> item = new ConsistencyItem<>(singletonList(propertyChain(property)), this);
1✔
26
        item.setComposer(new ComposerWrapper(LINK_COMPOSER, LINK_COMPOSER));
1✔
27
        item.setDecomposer(new DecomposerWrapper(LINK_DECOMPOSER, LINK_DECOMPOSER));
1✔
28
        return link(item);
1✔
29
    }
30

31
    default <P> C1<T, P> property(String property) {
32
        return new C1<>(this, new ConsistencyItem<>(singletonList(propertyChain(property)), this));
1✔
33
    }
34

35
    default <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
36
        return new C2<>(this, new ConsistencyItem<>(asList(propertyChain(property1), propertyChain(property2)), this));
1✔
37
    }
38

39
    interface Identity {
40
        default Object identity() {
NEW
41
            return this;
×
42
        }
43

44
        default boolean same(Identity another) {
NEW
45
            return identity() == another;
×
46
        }
47

48
        StackTraceElement getLocation();
49
    }
50

51
    interface Composer<T> extends Function<Object[], T>, Identity {
52
    }
53

54
    interface Decomposer<T> extends Function<T, Object[]>, Identity {
55
    }
56

57
    class DecorateConsistency<T> implements Consistency<T> {
58
        private final Consistency<T> consistency;
59

60
        public DecorateConsistency(Consistency<T> consistency) {
1✔
61
            this.consistency = consistency;
1✔
62
        }
1✔
63

64
        @Override
65
        public Consistency<T> link(ConsistencyItem<T> item) {
66
            return consistency.link(item);
1✔
67
        }
68

69
        @Override
70
        public void apply(Producer<?> producer) {
71
            consistency.apply(producer);
×
72
        }
×
73

74
        @Override
75
        public BeanClass<T> type() {
NEW
76
            return consistency.type();
×
77
        }
78

79
        @Override
80
        public Consistency<T> direct(String property) {
81
            return consistency.direct(property);
×
82
        }
83

84
        @Override
85
        public <P> C1<T, P> property(String property) {
86
            return consistency.property(property);
×
87
        }
88

89
        @Override
90
        public <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
91
            return consistency.properties(property1, property2);
1✔
92
        }
93
    }
94

95
    class C1<T, P> extends DecorateConsistency<T> {
96
        private final ConsistencyItem<T> lastItem;
97

98
        public C1(Consistency<T> origin, ConsistencyItem<T> lastItem) {
99
            super(origin);
1✔
100
            link(this.lastItem = lastItem);
1✔
101
        }
1✔
102

103
        @SuppressWarnings("unchecked")
104
        public C1<T, P> compose(Function<P, T> composer) {
105
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P) objs[0]), composer));
1✔
106
            return this;
1✔
107
        }
108

109
        public C1<T, P> decompose(Function<T, P> decomposer) {
110
            lastItem.setDecomposer(new DecomposerWrapper<>(t -> new Object[]{decomposer.apply(t)}, decomposer));
1✔
111
            return this;
1✔
112
        }
113
    }
114

115
    class MultiPropertyConsistency<T, C extends MultiPropertyConsistency<T, C>> extends DecorateConsistency<T> {
116
        protected final ConsistencyItem<T> lastItem;
117

118
        public MultiPropertyConsistency(Consistency<T> origin, ConsistencyItem<T> lastItem) {
119
            super(origin);
1✔
120
            this.lastItem = lastItem;
1✔
121
            link(lastItem);
1✔
122
        }
1✔
123

124
        @SuppressWarnings("unchecked")
125
        public C compose(Function<Object[], T> composer) {
126
            lastItem.setComposer(new ComposerWrapper<>(composer, composer));
1✔
127
            return (C) this;
1✔
128
        }
129

130
        @SuppressWarnings("unchecked")
131
        public C decompose(Function<T, Object[]> decomposer) {
132
            lastItem.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
133
            return (C) this;
1✔
134
        }
135
    }
136

137
    class C2<T, P1, P2> extends MultiPropertyConsistency<T, C2<T, P1, P2>> {
138
        public C2(Consistency<T> origin, ConsistencyItem<T> lastItem) {
139
            super(origin, lastItem);
1✔
140
        }
1✔
141

142
        @SuppressWarnings("unchecked")
143
        public C2<T, P1, P2> compose(BiFunction<P1, P2, T> composer) {
144
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P1) objs[0], (P2) objs[1]), composer));
1✔
145
            return this;
1✔
146
        }
147

148
        public C2<T, P1, P2> decompose(Function<T, P1> decompose1, Function<T, P2> decompose2) {
149
            lastItem.setDecomposer(new DecomposerWrapper<>(
1✔
150
                    t -> new Object[]{decompose1.apply(t), decompose2.apply(t)}, asList(decompose1, decompose2)));
1✔
151
            return this;
1✔
152
        }
153
    }
154
}
155

156
class IdentityAction implements Consistency.Identity {
157
    protected final Object identity;
158
    protected StackTraceElement location;
159

160
    public IdentityAction(Object identity) {
1✔
161
        this.identity = Objects.requireNonNull(identity);
1✔
162
        StackTraceElement[] stackTrace = new Throwable().getStackTrace();
1✔
163
        location = stackTrace[3];
1✔
164
    }
1✔
165

166
    @Override
167
    public Object identity() {
NEW
168
        return identity;
×
169
    }
170

171
    @Override
172
    public StackTraceElement getLocation() {
173
        return location;
1✔
174
    }
175
}
176

177
class ComposerWrapper<T> extends IdentityAction implements Consistency.Composer<T> {
178
    private final Function<Object[], T> action;
179

180
    ComposerWrapper(Function<Object[], T> action, Object identity) {
181
        super(identity);
1✔
182
        this.action = Objects.requireNonNull(action);
1✔
183
    }
1✔
184

185
    @Override
186
    public T apply(Object[] objects) {
187
        return action.apply(objects);
1✔
188
    }
189
}
190

191
class DecomposerWrapper<T> extends IdentityAction implements Consistency.Decomposer<T> {
192
    private final Function<T, Object[]> action;
193

194
    DecomposerWrapper(Function<T, Object[]> action, Object identity) {
195
        super(identity);
1✔
196
        this.action = Objects.requireNonNull(action);
1✔
197
    }
1✔
198

199
    @Override
200
    public Object[] apply(T t) {
201
        return action.apply(t);
1✔
202
    }
203
}
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