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

leeonky / test-charm-java / 290

08 Sep 2025 03:25PM UTC coverage: 74.312% (-0.003%) from 74.315%
290

push

circleci

leeonky
Introduce PropertyWriterDecorator

10 of 25 new or added lines in 6 files covered. (40.0%)

20 existing lines in 10 files now uncovered.

8155 of 10974 relevant lines covered (74.31%)

0.74 hits per line

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

98.0
/jfactory/src/main/java/com/github/leeonky/jfactory/JFactory.java
1
package com.github.leeonky.jfactory;
2

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

7
import java.util.*;
8
import java.util.function.Consumer;
9
import java.util.function.Predicate;
10

11
import static com.github.leeonky.jfactory.DefaultBuilder.BuildFrom.SPEC;
12
import static com.github.leeonky.jfactory.DefaultBuilder.BuildFrom.TYPE;
13

14
public class JFactory {
15
    final AliasSetStore aliasSetStore = new AliasSetStore();
1✔
16
    private final FactorySet factorySet = new FactorySet();
1✔
17
    private final DataRepository dataRepository;
18
    private final Set<Predicate<PropertyWriter<?>>> ignoreDefaultValues = new LinkedHashSet<>();
1✔
19

20
    public JFactory() {
1✔
21
        dataRepository = new MemoryDataRepository();
1✔
22
    }
1✔
23

24
    public JFactory(DataRepository dataRepository) {
1✔
25
        this.dataRepository = dataRepository;
1✔
26
    }
1✔
27

28
    public DataRepository getDataRepository() {
29
        return dataRepository;
1✔
30
    }
31

32
    public <T> Factory<T> factory(Class<T> type) {
33
        return factory(BeanClass.create(type));
1✔
34
    }
35

36
    public <T> Factory<T> factory(BeanClass<T> type) {
37
        return factorySet.queryObjectFactory(type);
1✔
38
    }
39

40
    public <T> Builder<T> type(Class<T> type) {
41
        return type(BeanClass.create(type));
1✔
42
    }
43

44
    public <T> Builder<T> type(BeanClass<T> type) {
45
        return new DefaultBuilder<>(factorySet.queryObjectFactory(type), this, TYPE);
1✔
46
    }
47

48
    public <T> Builder<T> type(TypeReference<T> type) {
49
        return type(type.getType());
1✔
50
    }
51

52
    public <T, S extends Spec<T>> Builder<T> spec(Class<S> specClass) {
53
        return new DefaultBuilder<>((ObjectFactory<T>) specFactory(specClass), this, SPEC);
1✔
54
    }
55

56
    public <T, S extends Spec<T>> Builder<T> spec(Class<S> specClass, Consumer<S> trait) {
57
        return new DefaultBuilder<>(factorySet.createSpecFactory(specClass, trait), this, SPEC);
1✔
58
    }
59

60
    public <T, S extends Spec<T>> JFactory register(Class<S> specClass) {
61
        getPropertyAliasesInSpec(specClass).stream().filter(Objects::nonNull).forEach(propertyAliases -> {
1✔
62
            if (propertyAliases.value().length > 0) {
1✔
63
                AliasSetStore.AliasSet aliasSet = aliasOfSpec(specClass);
1✔
64
                for (PropertyAlias propertyAlias : propertyAliases.value())
1✔
65
                    aliasSet.alias(propertyAlias.alias(), propertyAlias.property());
1✔
66
            }
67
        });
1✔
68
        factorySet.registerSpecClassFactory(specClass);
1✔
69
        return this;
1✔
70
    }
71

72
    private List<PropertyAliases> getPropertyAliasesInSpec(Class<?> specClass) {
73
        return new ArrayList<PropertyAliases>() {{
1✔
74
            Class<?> superclass = specClass.getSuperclass();
1✔
75
            if (!superclass.equals(Object.class))
1✔
76
                addAll(getPropertyAliasesInSpec(superclass));
1✔
77
            add(specClass.getAnnotation(PropertyAliases.class));
1✔
78
        }};
1✔
79
    }
80

81
    public <T> Builder<T> spec(String... traitsAndSpec) {
82
        return new DefaultBuilder<>((ObjectFactory<T>) specFactory(traitsAndSpec[traitsAndSpec.length - 1]), this, SPEC)
1✔
83
                .traits(Arrays.copyOf(traitsAndSpec, traitsAndSpec.length - 1));
1✔
84
    }
85

86
    public <T> Factory<T> specFactory(String specName) {
87
        return factorySet.querySpecClassFactory(specName);
1✔
88
    }
89

90
    public <T, S extends Spec<T>> Factory<T> specFactory(Class<S> specClass) {
91
        register(specClass);
1✔
92
        return factorySet.querySpecClassFactory(specClass);
1✔
93
    }
94

95
    public <T> T create(Class<T> type) {
96
        return type(type).create();
1✔
97
    }
98

99
    public <T, S extends Spec<T>> T createAs(Class<S> spec) {
100
        return spec(spec).create();
1✔
101
    }
102

103
    public <T, S extends Spec<T>> T createAs(Class<S> spec, Consumer<S> trait) {
104
        return spec(spec, trait).create();
1✔
105
    }
106

107
    public <T> T createAs(String... traitsAndSpec) {
108
        return this.<T>spec(traitsAndSpec).create();
1✔
109
    }
110

111
    public <T> JFactory registerDefaultValueFactory(Class<T> type, DefaultValueFactory<T> factory) {
112
        factorySet.registerDefaultValueFactory(type, factory);
1✔
113
        return this;
1✔
114
    }
115

116
    public JFactory ignoreDefaultValue(Predicate<PropertyWriter<?>> ignoreProperty) {
117
        ignoreDefaultValues.add(ignoreProperty);
1✔
118
        return this;
1✔
119
    }
120

121
    <T> boolean shouldCreateDefaultValue(PropertyWriter<T> propertyWriter) {
122
        return ignoreDefaultValues.stream().noneMatch(p -> p.test(propertyWriter));
1✔
123
    }
124

125
    public AliasSetStore.AliasSet aliasOf(Class<?> type) {
126
        return aliasSetStore.aliasSet(BeanClass.create(type));
1✔
127
    }
128

129
    public <T, S extends Spec<T>> AliasSetStore.AliasSet aliasOfSpec(Class<S> specClass) {
130
        return aliasSetStore.specAliasSet(specClass);
1✔
131
    }
132

133
    public JFactory removeGlobalSpec(Class<?> type) {
134
        factorySet.removeGlobalSpec(BeanClass.create(type));
1✔
135
        return this;
1✔
136
    }
137

138
    public Set<String> specNames() {
UNCOV
139
        return factorySet.specNames();
×
140
    }
141
}
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