• 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

95.0
/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

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

19
    private Instance<T> instance;
20
    private BeanClass<T> type = null;
1✔
21

22
    private ObjectFactory<T> objectFactory;
23

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

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

39
    public void main() {
40
    }
1✔
41

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

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

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

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

76
    protected String getName() {
77
        return getClass().getSimpleName();
1✔
78
    }
79

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

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

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

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

97
    public Arguments params() {
UNCOV
98
        return instance.params();
×
99
    }
100

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

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

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

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

123
    <V> PropertySpec<T>.IsSpec2<V> newIsSpec(String[] traitsAndSpec, PropertySpec<T> propertySpec) {
124
        PropertySpec<T>.IsSpec2<V> isSpec = propertySpec.new IsSpec2<V>(traitsAndSpec);
1✔
125
        invalidIsSpec2s.add(isSpec);
1✔
126
        return isSpec;
1✔
127
    }
128

129
    void consume(PropertySpec<T>.IsSpec2<?> isSpec) {
130
        invalidIsSpec2s.remove(isSpec);
1✔
131
    }
1✔
132

133
    void append(Spec<T> spec) {
134
        operations.addAll(spec.operations);
1✔
135
        invalidIsSpecs.addAll(spec.invalidIsSpecs);
1✔
136
    }
1✔
137

138
    public Spec<T> link(String propertyChain1, String propertyChain2, String... others) {
139
        Consistency<?> consistency = consistent(Object.class);
1✔
140
        consistency.direct(propertyChain1)
1✔
141
                .direct(propertyChain2);
1✔
142
        for (String string : others)
1✔
143
            consistency.direct(string);
1✔
144
        return this;
1✔
145
    }
146

147
    public <V> Consistency<V> consistent(Class<V> type) {
148
        DefaultConsistency<V> consistency = new DefaultConsistency<>(type);
1✔
149
        append((jFactory, objectProducer) -> objectProducer.appendLink(consistency));
1✔
150
        return consistency;
1✔
151
    }
152
}
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