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

leeonky / test-charm-java / 323

30 Sep 2025 05:15PM UTC coverage: 74.637% (+0.1%) from 74.512%
323

push

circleci

leeonky
Use descendantForRead in consistent provider

16 of 17 new or added lines in 4 files covered. (94.12%)

29 existing lines in 7 files now uncovered.

8531 of 11430 relevant lines covered (74.64%)

0.75 hits per line

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

93.75
/jfactory/src/main/java/com/github/leeonky/jfactory/Producer.java
1
package com.github.leeonky.jfactory;
2

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

6
import java.util.Optional;
7
import java.util.function.BiFunction;
8

9
import static java.util.Optional.ofNullable;
10
import static java.util.function.Function.identity;
11

12
abstract class Producer<T> {
13
    private final BeanClass<T> type;
14
    private final ValueCache<T> valueCache = new ValueCache<>();
1✔
15

16
    protected Producer(BeanClass<T> type) {
1✔
17
        this.type = type;
1✔
18
    }
1✔
19

20
    public BeanClass<T> getType() {
21
        return type;
1✔
22
    }
23

24
    protected abstract T produce();
25

26
    public T getValue() {
27
        return valueCache.cache(this::produce);
1✔
28
    }
29

30
    protected void collectConsistent(ObjectProducer<?> root, PropertyChain base) {
31
    }
1✔
32

33
    public Optional<Producer<?>> getChild(String property) {
34
        return Optional.empty();
1✔
35
    }
36

37
    protected void setChild(String property, Producer<?> producer) {
38
    }
1✔
39

40
    public Producer<?> childForUpdate(String property) {
41
        return getChild(property).orElse(null);
1✔
42
    }
43

44
    public Producer<?> childForRead(String property) {
45
        return getChild(property).orElseGet(() -> new ReadOnlyProducer<>(this, property));
1✔
46
    }
47

48
    @SuppressWarnings("unchecked")
49
    public <T> void changeChild(String property, Producer<T> producer) {
50
        Producer<T> origin = (Producer<T>) childForUpdate(property);
1✔
51
        if (origin != producer)
1✔
52
            setChild(property, origin == null ? producer : origin.changeTo(producer));
1✔
53
    }
1✔
54

55
    public Producer<?> descendantForRead(PropertyChain property) {
56
        return property.access(this, Producer::childForRead, identity());
1✔
57
    }
58

59
    public Producer<?> descendantForUpdate(PropertyChain property) {
60
        return property.access(this, (producer, subProperty) -> ofNullable(producer.childForUpdate(subProperty))
1✔
61
                .orElseGet(() -> new ReadOnlyProducer<>(producer, subProperty)), identity());
1✔
62
    }
63

64
    public void changeDescendant(PropertyChain property, BiFunction<Producer<?>, String, Producer<?>> producerFactory) {
65
        String tail = property.tail();
1✔
66
        property.removeTail().access(this, Producer::childForUpdate, Optional::ofNullable).ifPresent(lastObjectProducer ->
1✔
67
                lastObjectProducer.changeChild(tail, producerFactory.apply(lastObjectProducer, tail)));
1✔
68
    }
1✔
69

70
    public BeanClass<?> getPropertyWriterType(String property) {
71
        return getType().getPropertyWriter(property).getType();
1✔
72
    }
73

74
    public Optional<Producer<?>> newDefaultValueProducer(PropertyWriter<?> property) {
75
        return Optional.empty();
×
76
    }
77

78
    public Producer<T> changeTo(Producer<T> newProducer) {
79
        return newProducer.reChangeFrom(this);
1✔
80
    }
81

82
    protected Producer<T> reChangeFrom(Producer<T> producer) {
83
        return this;
1✔
84
    }
85

86
    protected Producer<T> changeFrom(ObjectProducer<T> producer) {
87
        return this;
1✔
88
    }
89

90
    protected Producer<T> changeFrom(OptionalSpecDefaultValueProducer<T> producer) {
UNCOV
91
        return this;
×
92
    }
93

94
    protected Producer<T> reChangeTo(DefaultValueProducer<T> newProducer) {
95
        return this;
1✔
96
    }
97

98
    protected Producer<T> reChangeTo(ConsistencyProducer<T, ?> newProducer) {
99
        return newProducer;
1✔
100
    }
101

102
    protected <R> void setupAssociation(String association, RootInstance<R> instance, ListPersistable cachedChildren) {
103
    }
1✔
104

105
    protected boolean isFixed() {
106
        return false;
1✔
107
    }
108
}
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