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

leeonky / test-charm-java / 320

28 Sep 2025 03:56PM UTC coverage: 74.512% (+0.07%) from 74.442%
320

push

circleci

leeonky
one list one property

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

13 existing lines in 7 files now uncovered.

8466 of 11362 relevant lines covered (74.51%)

0.75 hits per line

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

96.2
/jfactory/src/main/java/com/github/leeonky/jfactory/AbstractConsistency.java
1
package com.github.leeonky.jfactory;
2

3
import com.github.leeonky.util.BeanClass;
4
import com.github.leeonky.util.function.TriFunction;
5

6
import java.util.Arrays;
7
import java.util.Objects;
8
import java.util.function.BiFunction;
9
import java.util.function.Function;
10

11
import static com.github.leeonky.jfactory.ConsistencyItem.guessCustomerPositionStackTrace;
12
import static com.github.leeonky.jfactory.PropertyChain.propertyChain;
13
import static com.sun.jmx.mbeanserver.Util.cast;
14
import static java.util.Arrays.asList;
15
import static java.util.Collections.singletonList;
16
import static java.util.stream.Collectors.toList;
17

18
abstract class AbstractConsistency<T> implements Consistency<T> {
1✔
19
    static final Function<Object[], ?> LINK_COMPOSER = objs -> objs[0];
1✔
20
    static final Function<?, Object[]> LINK_DECOMPOSER = t -> new Object[]{t};
1✔
21

22
    abstract Consistency<T> link(ConsistencyItem<T> item);
23

24
    abstract BeanClass<T> type();
25

26
    @Override
27
    public Consistency<T> direct(String property) {
28
        ConsistencyItem<T> item = new ConsistencyItem<>(singletonList(propertyChain(property)), this);
1✔
29
        item.setComposer(cast(new ComposerWrapper<>(LINK_COMPOSER, LINK_COMPOSER)));
1✔
30
        item.setDecomposer(cast(new DecomposerWrapper<>(LINK_DECOMPOSER, LINK_DECOMPOSER)));
1✔
31
        return link(item);
1✔
32
    }
33

34
    @Override
35
    public <P> C1<T, P> property(String property) {
36
        return new C1<>(this, new ConsistencyItem<>(singletonList(propertyChain(property)), this));
1✔
37
    }
38

39
    @Override
40
    public <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
41
        return new C2<>(this, new ConsistencyItem<>(asList(propertyChain(property1), propertyChain(property2)), this));
1✔
42
    }
43

44
    @Override
45
    public <P1, P2, P3> C3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
46
        return new C3<>(this, new ConsistencyItem<>(asList(propertyChain(property1), propertyChain(property2), propertyChain(property3)), this));
1✔
47
    }
48

49
    @Override
50
    public CN<T> properties(String... properties) {
51
        return new CN<>(this, new ConsistencyItem<>(Arrays.stream(properties).map(PropertyChain::propertyChain).collect(toList()), this));
1✔
52
    }
53

54
    public interface Identity {
55
        default Object identity() {
56
            return this;
×
57
        }
58

59
        default boolean same(Identity another) {
60
            return another != null && identity() == another.identity();
1✔
61
        }
62

63
        StackTraceElement getLocation();
64

65
        static boolean isSame(Identity identity1, Identity identity2) {
66
            return identity1 != null && identity2 != null && identity1.same(identity2);
1✔
67
        }
68

69
        static boolean isBothNull(Identity identity1, Identity identity2) {
70
            return identity1 == null && identity2 == null;
1✔
71
        }
72
    }
73

74
    public interface Composer<T> extends Function<Object[], T>, Identity {
75
    }
76

77
    public interface Decomposer<T> extends Function<T, Object[]>, Identity {
78
    }
79

80
    public static class DecorateConsistency<T> extends AbstractConsistency<T> {
81
        private final AbstractConsistency<T> consistency;
82

83
        DecorateConsistency(AbstractConsistency<T> consistency) {
1✔
84
            this.consistency = consistency;
1✔
85
        }
1✔
86

87
        @Override
88
        Consistency<T> link(ConsistencyItem<T> item) {
89
            return consistency.link(item);
1✔
90
        }
91

92
        @Override
93
        BeanClass<T> type() {
94
            return consistency.type();
×
95
        }
96

97
        @Override
98
        public Consistency<T> direct(String property) {
99
            return consistency.direct(property);
1✔
100
        }
101

102
        @Override
103
        public <P> C1<T, P> property(String property) {
104
            return consistency.property(property);
1✔
105
        }
106

107
        @Override
108
        public <P1, P2> C2<T, P1, P2> properties(String property1, String property2) {
109
            return consistency.properties(property1, property2);
1✔
110
        }
111

112
        @Override
113
        public <P1, P2, P3> C3<T, P1, P2, P3> properties(String property1, String property2, String property3) {
114
            return consistency.properties(property1, property2, property3);
1✔
115
        }
116

117
        @Override
118
        public CN<T> properties(String... properties) {
119
            return consistency.properties(properties);
1✔
120
        }
121

122
        @Override
123
        public ListConsistency<T> list(String property) {
UNCOV
124
            return consistency.list(property);
×
125
        }
126
    }
127

128
    public static class C1<T, P> extends DecorateConsistency<T> {
129
        private final ConsistencyItem<T> lastItem;
130

131
        C1(AbstractConsistency<T> origin, ConsistencyItem<T> lastItem) {
132
            super(origin);
1✔
133
            link(this.lastItem = lastItem);
1✔
134
        }
1✔
135

136
        @SuppressWarnings("unchecked")
137
        public C1<T, P> read(Function<P, T> composer) {
138
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P) objs[0]), composer));
1✔
139
            return this;
1✔
140
        }
141

142
        public C1<T, P> write(Function<T, P> decomposer) {
143
            lastItem.setDecomposer(new DecomposerWrapper<>(t -> new Object[]{decomposer.apply(t)}, decomposer));
1✔
144
            return this;
1✔
145
        }
146
    }
147

148
    public static class MultiPropertyConsistency<T, C extends MultiPropertyConsistency<T, C>> extends DecorateConsistency<T> {
149
        final ConsistencyItem<T> lastItem;
150

151
        MultiPropertyConsistency(AbstractConsistency<T> origin, ConsistencyItem<T> lastItem) {
152
            super(origin);
1✔
153
            this.lastItem = lastItem;
1✔
154
            link(lastItem);
1✔
155
        }
1✔
156

157
        @SuppressWarnings("unchecked")
158
        public C read(Function<Object[], T> composer) {
159
            lastItem.setComposer(new ComposerWrapper<>(composer, composer));
1✔
160
            return (C) this;
1✔
161
        }
162

163
        @SuppressWarnings("unchecked")
164
        public C write(Function<T, Object[]> decomposer) {
165
            lastItem.setDecomposer(new DecomposerWrapper<>(decomposer, decomposer));
1✔
166
            return (C) this;
1✔
167
        }
168
    }
169

170
    public static class C2<T, P1, P2> extends MultiPropertyConsistency<T, C2<T, P1, P2>> {
171
        C2(AbstractConsistency<T> origin, ConsistencyItem<T> lastItem) {
172
            super(origin, lastItem);
1✔
173
        }
1✔
174

175
        @SuppressWarnings("unchecked")
176
        public C2<T, P1, P2> read(BiFunction<P1, P2, T> composer) {
177
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P1) objs[0], (P2) objs[1]), composer));
1✔
178
            return this;
1✔
179
        }
180

181
        public C2<T, P1, P2> write(Function<T, P1> decompose1, Function<T, P2> decompose2) {
182
            lastItem.setDecomposer(new DecomposerWrapper<>(
1✔
183
                    t -> new Object[]{decompose1.apply(t), decompose2.apply(t)}, asList(decompose1, decompose2)));
1✔
184
            return this;
1✔
185
        }
186
    }
187

188
    public static class C3<T, P1, P2, P3> extends MultiPropertyConsistency<T, C3<T, P1, P2, P3>> {
189
        C3(AbstractConsistency<T> origin, ConsistencyItem<T> lastItem) {
190
            super(origin, lastItem);
1✔
191
        }
1✔
192

193
        @SuppressWarnings("unchecked")
194
        public C3<T, P1, P2, P3> read(TriFunction<P1, P2, P3, T> composer) {
195
            lastItem.setComposer(new ComposerWrapper<>(objs -> composer.apply((P1) objs[0], (P2) objs[1], (P3) objs[2]), composer));
1✔
196
            return this;
1✔
197
        }
198

199
        public C3<T, P1, P2, P3> write(Function<T, P1> decompose1, Function<T, P2> decompose2, Function<T, P3> decompose3) {
200
            lastItem.setDecomposer(new DecomposerWrapper<>(
1✔
201
                    t -> new Object[]{decompose1.apply(t), decompose2.apply(t), decompose3.apply(t)},
1✔
202
                    asList(decompose1, decompose2, decompose3)));
1✔
203
            return this;
1✔
204
        }
205
    }
206

207
    public static class CN<T> extends MultiPropertyConsistency<T, CN<T>> {
208
        CN(AbstractConsistency<T> origin, ConsistencyItem<T> lastItem) {
209
            super(origin, lastItem);
1✔
210
        }
1✔
211
    }
212

213
    public static class LC1<T, P> extends DecorateConsistency<T> {
214
        private final DefaultListConsistency<T> lastListConsistency;
215

216
        LC1(AbstractConsistency<T> origin, DefaultListConsistency<T> lastListConsistency) {
217
            super(origin);
1✔
218
            this.lastListConsistency = lastListConsistency;
1✔
219
        }
1✔
220

221
        public LC1<T, P> read(Function<P, T> composer) {
222
            lastListConsistency.setComposer(new ComposerWrapper<>(objs -> composer.apply((P) objs[0]), composer));
1✔
223
            return this;
1✔
224
        }
225

226
        public LC1<T, P> write(Function<T, P> decomposer) {
227
            lastListConsistency.setDecomposer(new DecomposerWrapper<>(t -> new Object[]{decomposer.apply(t)}, decomposer));
1✔
228
            return this;
1✔
229
        }
230
    }
231
}
232

233
class IdentityAction implements AbstractConsistency.Identity {
234
    protected final Object identity;
235
    private final StackTraceElement location;
236

237
    public IdentityAction(Object identity) {
1✔
238
        this.identity = Objects.requireNonNull(identity);
1✔
239
        location = guessCustomerPositionStackTrace();
1✔
240
    }
1✔
241

242
    @Override
243
    public Object identity() {
244
        return identity;
1✔
245
    }
246

247
    @Override
248
    public StackTraceElement getLocation() {
249
        return location;
1✔
250
    }
251
}
252

253
class ComposerWrapper<T> extends IdentityAction implements AbstractConsistency.Composer<T> {
254
    private final Function<Object[], T> action;
255

256
    ComposerWrapper(Function<Object[], T> action, Object identity) {
257
        super(identity);
1✔
258
        this.action = Objects.requireNonNull(action);
1✔
259
    }
1✔
260

261
    @Override
262
    public T apply(Object[] objects) {
263
        return action.apply(objects);
1✔
264
    }
265
}
266

267
class DecomposerWrapper<T> extends IdentityAction implements AbstractConsistency.Decomposer<T> {
268
    private final Function<T, Object[]> action;
269

270
    DecomposerWrapper(Function<T, Object[]> action, Object identity) {
271
        super(identity);
1✔
272
        this.action = Objects.requireNonNull(action);
1✔
273
    }
1✔
274

275
    @Override
276
    public Object[] apply(T t) {
277
        return action.apply(t);
1✔
278
    }
279
}
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