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

leeonky / test-charm-java / 311

27 Sep 2025 10:36AM UTC coverage: 74.329% (+3.1%) from 71.191%
311

push

circleci

leeonky
Remove useless code

4 of 4 new or added lines in 3 files covered. (100.0%)

43 existing lines in 9 files now uncovered.

8397 of 11297 relevant lines covered (74.33%)

0.74 hits per line

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

93.98
/jfactory/src/main/java/com/github/leeonky/jfactory/PropertySpec.java
1
package com.github.leeonky.jfactory;
2

3
import com.github.leeonky.util.BeanClass;
4
import com.github.leeonky.util.GenericBeanClass;
5
import com.github.leeonky.util.PropertyWriter;
6

7
import java.util.List;
8
import java.util.function.Consumer;
9
import java.util.function.Function;
10
import java.util.function.Supplier;
11

12
import static java.lang.String.format;
13

14
public class PropertySpec<T> {
15
    private final Spec<T> spec;
16
    private final PropertyChain property;
17

18
    PropertySpec(Spec<T> spec, PropertyChain property) {
1✔
19
        this.spec = spec;
1✔
20
        this.property = property;
1✔
21
    }
1✔
22

23
    public Spec<T> value(Object value) {
24
        return value(() -> value);
1✔
25
    }
26

27
    @SuppressWarnings("unchecked")
28
    public <V> Spec<T> value(Supplier<V> value) {
29
        if (value == null)
1✔
30
            return value(() -> null);
1✔
31
        return appendProducer((jFactory, producer, property) ->
1✔
32
                new UnFixedValueProducer<>(value, (BeanClass<V>) producer.getPropertyWriterType(property)));
1✔
33
    }
34

35
    @Deprecated
36
    /**
37
     * reference spec and trait via string
38
     */
39
    public <V> Spec<T> is(Class<? extends Spec<V>> specClass) {
40
        return appendProducer(jFactory -> createCreateProducer(jFactory.spec(specClass)));
1✔
41
    }
42

43
    public Spec<T> is(String... traitsAndSpec) {
44
        return appendProducer(jFactory -> createCreateProducer(jFactory.spec(traitsAndSpec)));
1✔
45
    }
46

47
    public <V> IsSpec2<V> from(String... traitsAndSpec) {
48
        return spec.newIsSpec(traitsAndSpec, this);
1✔
49
    }
50

51
    @Deprecated
52
    /**
53
     * reference spec and trait via string
54
     */
55
    public <V, S extends Spec<V>> IsSpec<V, S> from(Class<S> specClass) {
56
        return spec.newIsSpec(specClass, this);
1✔
57
    }
58

59
    public Spec<T> defaultValue(Object value) {
60
        return defaultValue(() -> value);
1✔
61
    }
62

63
    @SuppressWarnings("unchecked")
64
    public <V> Spec<T> defaultValue(Supplier<V> supplier) {
65
        if (supplier == null)
1✔
UNCOV
66
            return defaultValue((Object) null);
×
67
        return appendProducer((jFactory, producer, property) ->
1✔
68
                new DefaultValueProducer<>((BeanClass<V>) producer.getPropertyWriterType(property), supplier));
1✔
69
    }
70

71
    public Spec<T> byFactory() {
72
        return appendProducer((jFactory, producer, property) ->
1✔
73
                producer.createPropertyDefaultValueProducer(producer.getType().getPropertyWriter(property)).orElseGet(() ->
1✔
74
                        createCreateProducer(jFactory.type(producer.getPropertyWriterType(property).getType()))));
1✔
75
    }
76

77
    public Spec<T> byFactory(Function<Builder<?>, Builder<?>> builder) {
78
        return appendProducer((jFactory, producer, property) ->
1✔
79
                producer.createPropertyDefaultValueProducer(producer.getType().getPropertyWriter(property))
1✔
80
                        .orElseGet(() -> createQueryOrCreateProducer(builder.apply(jFactory.type(
1✔
81
                                producer.getPropertyWriterType(property).getType())))));
1✔
82
    }
83

84
    public Spec<T> dependsOn(String dependency) {
UNCOV
85
        spec.consistent(Object.class)
×
UNCOV
86
                .property(property.toString()).write(Function.identity())
×
UNCOV
87
                .property(dependency).read(Function.identity());
×
UNCOV
88
        return spec;
×
89
    }
90

91
    public Spec<T> dependsOn(String dependency, Function<Object, Object> rule) {
92
        spec.consistent(Object.class)
1✔
93
                .property(property.toString()).write(Function.identity())
1✔
94
                .property(dependency).read(rule);
1✔
95
        return spec;
1✔
96
    }
97

98
    public Spec<T> dependsOn(List<String> dependencies, Function<Object[], Object> rule) {
99
        spec.consistent(Object.class)
1✔
100
                .property(property.toString()).write(Function.identity())
1✔
101
                .properties(dependencies.toArray(new String[0])).read(rule);
1✔
102
        return spec;
1✔
103
    }
104

105
    private Spec<T> appendProducer(Fuc<JFactory, Producer<?>, String, Producer<?>> producerFactory) {
106
        if (property.isSingle() || property.isTopLevelPropertyCollection())
1✔
107
            return spec.append((jFactory, objectProducer) -> {
1✔
108
                objectProducer.changeDescendant(property, ((nextToLast, property) -> producerFactory.apply(jFactory, nextToLast, property)));
1✔
109
            });
1✔
110
        if (property.isDefaultPropertyCollection()) {
1✔
111
            return spec.append((jFactory, objectProducer) -> {
1✔
112
                PropertyWriter<T> propertyWriter = objectProducer.getType().getPropertyWriter((String) property.head());
1✔
113
                if (!propertyWriter.getType().isCollection() && propertyWriter.getType().is(Object.class)) {
1✔
114
                    Producer<?> element = producerFactory.apply(jFactory, objectProducer, "0");
1✔
115
                    propertyWriter = propertyWriter.decorateType(GenericBeanClass.create(List.class, element.getType().getGenericType()));
1✔
116
                }
117
                CollectionProducer<?, ?> collectionProducer = BeanClass.cast(objectProducer.childOrDefaultCollection(propertyWriter, true),
1✔
118
                        CollectionProducer.class).orElseThrow(() ->
1✔
119
                        new IllegalArgumentException(format("%s.%s is not list", spec.getType().getName(), property.head())));
1✔
120
                collectionProducer.changeElementDefaultValueProducerFactory(index ->
1✔
121
                        producerFactory.apply(jFactory, collectionProducer, index.toString()));
1✔
122
            });
1✔
123
        }
124
        if (property.isTopLevelDefaultPropertyCollection()) {
1✔
125
            return spec.append((jFactory, objectProducer) -> {
1✔
126
                objectProducer.changeElementDefaultValueProducerFactory(propertyWriter ->
1✔
127
                        producerFactory.apply(jFactory, objectProducer, propertyWriter.getName()));
1✔
128
            });
1✔
129
        }
130
        throw new IllegalArgumentException(format("Not support property chain '%s' in current operation", property));
1✔
131
    }
132

133
    private Spec<T> appendProducer(Function<JFactory, Producer<?>> producerFactory) {
134
        return appendProducer((jFactory, producer, s) -> producerFactory.apply(jFactory));
1✔
135
    }
136

137
    @SuppressWarnings("unchecked")
138
    private <V> Producer<V> createQueryOrCreateProducer(Builder<V> builder) {
139
        Builder<V> builderWithArgs = builder.args(spec.params(property.toString()));
1✔
140
        return builderWithArgs.queryAll().stream().findFirst().<Producer<V>>map(object ->
1✔
141
                        new BuilderValueProducer<>((BeanClass<V>) BeanClass.create(object.getClass()), builderWithArgs))
1✔
142
                .orElseGet(builderWithArgs::createProducer);
1✔
143
    }
144

145
    private <V> Producer<V> createCreateProducer(Builder<V> builder) {
146
        return builder.args(spec.params(property.toString())).createProducer();
1✔
147
    }
148

149
    public Spec<T> reverseAssociation(String association) {
150
        return spec.append((jFactory, producer) -> producer.appendReverseAssociation(property, association));
1✔
151
    }
152

153
    public Spec<T> ignore() {
154
        return spec.append((jFactory, objectProducer) -> objectProducer.ignoreProperty(property.toString()));
1✔
155
    }
156

157
    @FunctionalInterface
158
    interface Fuc<P1, P2, P3, R> {
159
        R apply(P1 p1, P2 p2, P3 p3);
160
    }
161

162
    public class IsSpec<V, S extends Spec<V>> {
163
        private final Class<S> specClass;
164
        private final String position;
165

166
        public IsSpec(Class<S> spec) {
1✔
167
            position = Thread.currentThread().getStackTrace()[4].toString();
1✔
168
            specClass = spec;
1✔
169
        }
1✔
170

171
        public Spec<T> which(Consumer<S> trait) {
172
            spec.consume(this);
1✔
173
            return appendProducer(jFactory -> createCreateProducer(jFactory.spec(specClass, trait)));
1✔
174
        }
175

176
        public Spec<T> and(Function<Builder<V>, Builder<V>> builder) {
177
            spec.consume(this);
1✔
178
            return appendProducer(jFactory -> createQueryOrCreateProducer(builder.apply(jFactory.spec(specClass))));
1✔
179
        }
180

181
        public String getPosition() {
182
            return position;
1✔
183
        }
184
    }
185

186
    public class IsSpec2<V> {
187
        private final String[] spec;
188
        private final String position;
189

190
        public IsSpec2(String[] spec) {
1✔
191
            position = Thread.currentThread().getStackTrace()[4].toString();
1✔
192
            this.spec = spec;
1✔
193
        }
1✔
194

195
        public Spec<T> and(Function<Builder<V>, Builder<V>> builder) {
196
            PropertySpec.this.spec.consume(this);
1✔
197
            return appendProducer(jFactory -> createQueryOrCreateProducer(builder.apply(jFactory.spec(spec))));
1✔
198
        }
199

200
        public String getPosition() {
201
            return position;
1✔
202
        }
203
    }
204
}
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