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

leeonky / test-charm-java / 293

12 Sep 2025 04:43PM UTC coverage: 74.22% (-0.09%) from 74.312%
293

push

circleci

leeonky
create sub list from spec list in spec

33 of 42 new or added lines in 8 files covered. (78.57%)

32 existing lines in 11 files now uncovered.

8234 of 11094 relevant lines covered (74.22%)

0.74 hits per line

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

93.33
/jfactory/src/main/java/com/github/leeonky/jfactory/Spec.java
1
package com.github.leeonky.jfactory;
2

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

5
import java.util.ArrayList;
6
import java.util.LinkedHashSet;
7
import java.util.List;
8
import java.util.Set;
9
import java.util.function.BiConsumer;
10
import java.util.stream.Collectors;
11

12
import static com.github.leeonky.jfactory.PropertyChain.propertyChain;
13
import static java.util.stream.Collectors.toList;
14
import static java.util.stream.Stream.concat;
15
import static java.util.stream.Stream.of;
16

17
public class Spec<T> {
1✔
18
    private final List<BiConsumer<JFactory, ObjectProducer<T>>> operations = new ArrayList<>();
1✔
19
    private final Set<PropertySpec<T>.IsSpec<?, ? extends Spec<?>>> invalidIsSpecs = new LinkedHashSet<>();
1✔
20

21
    private Instance<T> instance;
22
    private BeanClass<T> type = null;
1✔
23

24
    private ObjectFactory<T> objectFactory;
25

26
    T constructBy(ObjectFactory<T> factory) {
27
        objectFactory = factory;
1✔
28
        try {
29
            if (objectFactory == null)
1✔
UNCOV
30
                throw new IllegalStateException("Illegal construct context");
×
31
            return construct();
1✔
32
        } finally {
33
            objectFactory = null;
1✔
34
        }
35
    }
36

37
    protected T construct() {
38
        return objectFactory.getBase().create(instance);
1✔
39
    }
40

41
    public void main() {
42
    }
1✔
43

44
    public PropertySpec<T> property(String property) {
45
        return new PropertySpec<>(this, propertyChain(property));
1✔
46
    }
47

48
    Spec<T> append(BiConsumer<JFactory, ObjectProducer<T>> operation) {
49
        operations.add(operation);
1✔
50
        return this;
1✔
51
    }
52

53
    void apply(JFactory jFactory, ObjectProducer<T> producer) {
54
        operations.forEach(o -> o.accept(jFactory, producer));
1✔
55
        type = producer.getType();
1✔
56
        if (!invalidIsSpecs.isEmpty())
1✔
57
            throw new InvalidSpecException("Invalid property spec:\n\t"
1✔
58
                    + invalidIsSpecs.stream().map(PropertySpec.IsSpec::getPosition).collect(Collectors.joining("\n\t"))
1✔
59
                    + "\nShould finish method chain with `and` or `which`:\n"
60
                    + "\tproperty().from().which()\n"
61
                    + "\tproperty().from().and()\n"
62
                    + "Or use property().is() to create object with only spec directly.");
63
    }
1✔
64

65
    @SuppressWarnings("unchecked")
66
    public BeanClass<T> getType() {
67
        return getClass().equals(Spec.class) ? type :
1✔
68
                (BeanClass<T>) BeanClass.create(getClass()).getSuper(Spec.class).getTypeArguments(0)
1✔
69
                        .orElseThrow(() -> new IllegalStateException("Cannot guess type via generic type argument, please override Spec::getType"));
1✔
70
    }
71

72
    protected String getName() {
73
        return getClass().getSimpleName();
1✔
74
    }
75

76
    public Spec<T> link(String property, String... others) {
77
        List<PropertyChain> linkProperties = concat(of(property), of(others)).map(PropertyChain::propertyChain).collect(toList());
1✔
78
        append((jFactory, objectProducer) -> objectProducer.link(linkProperties));
1✔
79
        return this;
1✔
80
    }
81

82
    Spec<T> setInstance(Instance<T> instance) {
83
        this.instance = instance;
1✔
84
        return this;
1✔
85
    }
86

87
    public <P> P param(String key) {
88
        return instance.param(key);
1✔
89
    }
90

91
    public <P> P param(String key, P defaultValue) {
UNCOV
92
        return instance.param(key, defaultValue);
×
93
    }
94

95
    public Arguments params(String property) {
96
        return instance.params(property);
1✔
97
    }
98

99
    public Arguments params() {
UNCOV
100
        return instance.params();
×
101
    }
102

103
    public Instance<T> instance() {
104
        return instance;
1✔
105
    }
106

107
    public Spec<T> ignore(String... properties) {
108
        for (String property : properties)
1✔
109
            property(property).ignore();
1✔
110
        return this;
1✔
111
    }
112

113
    <V, S extends Spec<V>> PropertySpec<T>.IsSpec<V, S> newIsSpec(Class<S> specClass, PropertySpec<T> propertySpec) {
114
        PropertySpec<T>.IsSpec<V, S> isSpec = propertySpec.new IsSpec<V, S>(specClass);
1✔
115
        invalidIsSpecs.add(isSpec);
1✔
116
        return isSpec;
1✔
117
    }
118

119
    void consume(PropertySpec<T>.IsSpec<?, ? extends Spec<?>> isSpec) {
120
        invalidIsSpecs.remove(isSpec);
1✔
121
    }
1✔
122

123
    void append(Spec<T> spec) {
124
        operations.addAll(spec.operations);
1✔
125
        invalidIsSpecs.addAll(spec.invalidIsSpecs);
1✔
126
    }
1✔
127
}
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