• 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

96.43
/jfactory/src/main/java/com/github/leeonky/jfactory/TraitsSpec.java
1
package com.github.leeonky.jfactory;
2

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

5
import java.util.LinkedHashSet;
6
import java.util.Objects;
7
import java.util.Optional;
8
import java.util.Set;
9

10
import static java.util.Arrays.asList;
11

12
class TraitsSpec {
13
    private String spec;
14
    private final Set<String> traits;
15
    private boolean collectionSpec = false;
1✔
16

17
    public TraitsSpec(String[] traits, String spec) {
1✔
18
        setSpec(spec);
1✔
19
        this.traits = new LinkedHashSet<>(asList(traits));
1✔
20
    }
1✔
21

22
    private void mergeTraits(TraitsSpec another) {
23
        traits.addAll(another.traits);
1✔
24
    }
1✔
25

26
    private void mergeSpec(TraitsSpec another, String property) {
27
        if (isDifferentSpec(another))
1✔
28
            throw new IllegalArgumentException(String.format("Cannot merge different spec `%s` and `%s` for %s",
1✔
29
                    spec, another.spec, property));
30
        if (spec == null)
1✔
31
            setSpec(another.spec);
1✔
32
    }
1✔
33

34
    private void setSpec(String spec) {
35
        if (spec != null) {
1✔
36
            collectionSpec = spec.endsWith("[]");
1✔
37
            this.spec = spec.replace("[]", "");
1✔
38
        }
39
    }
1✔
40

41
    private boolean isDifferentSpec(TraitsSpec another) {
42
        return spec != null && another.spec != null && !Objects.equals(spec, another.spec);
1✔
43
    }
44

45
    public Builder<?> toBuilder(JFactory jFactory, BeanClass<?> propertyType) {
46
        return (spec != null ? jFactory.spec(spec) : jFactory.type(propertyType.getType()))
1✔
47
                .traits(traits.toArray(new String[0]));
1✔
48
    }
49

50
    public void merge(TraitsSpec another, String property) {
51
        mergeTraits(another);
1✔
52
        mergeSpec(another, property);
1✔
53
    }
1✔
54

55
    public Optional<BeanClass> guessPropertyType(ObjectFactory<?> objectFactory) {
56
        if (spec != null)
1✔
57
            return Optional.of(objectFactory.getFactorySet().querySpecClassFactory(spec).getType());
1✔
58
        return Optional.empty();
1✔
59
    }
60

61
    public boolean isCollectionSpec() {
62
        return collectionSpec;
1✔
63
    }
64

65
    public String spec() {
66
        return spec;
1✔
67
    }
68

69
    public boolean isEmpty() {
UNCOV
70
        return spec == null;
×
71
    }
72
}
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