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

leeonky / test-charm-java / 249

12 May 2025 09:46AM UTC coverage: 74.26% (-0.03%) from 74.288%
249

push

circleci

leeonky
Rename

3 of 3 new or added lines in 3 files covered. (100.0%)

21 existing lines in 5 files now uncovered.

8075 of 10874 relevant lines covered (74.26%)

0.74 hits per line

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

87.76
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/schema/Actual.java
1
package com.github.leeonky.dal.runtime.schema;
2

3
import com.github.leeonky.dal.compiler.Compiler;
4
import com.github.leeonky.dal.format.Formatter;
5
import com.github.leeonky.dal.format.Type;
6
import com.github.leeonky.dal.format.Value;
7
import com.github.leeonky.dal.runtime.DALRuntimeException;
8
import com.github.leeonky.dal.runtime.Data;
9
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
10
import com.github.leeonky.dal.type.Schema;
11
import com.github.leeonky.dal.type.SubType;
12
import com.github.leeonky.util.BeanClass;
13

14
import java.util.Objects;
15
import java.util.function.Function;
16
import java.util.stream.Stream;
17

18
import static com.github.leeonky.util.Classes.getClassName;
19
import static java.lang.String.format;
20
import static java.util.Optional.ofNullable;
21

22
public class Actual {
23
    private final String property;
24
    private final Data<?> actual;
25

26
    public Actual(String property, Data<?> actual) {
1✔
27
        this.property = property;
1✔
28
        this.actual = actual;
1✔
29
    }
1✔
30

31
    public static Actual actual(Data<?> data) {
32
        return new Actual("", data);
1✔
33
    }
34

35
    public Actual sub(Object property) {
36
        return new Actual(this.property + "." + property, actual.property(property));
1✔
37
    }
38

39
    public boolean isNull() {
40
        return actual.isNull();
1✔
41
    }
42

43
    public Actual sub(Integer index) {
UNCOV
44
        return new Actual(property + "[" + index + "]", actual.property(index));
×
45
    }
46

47
    private final static Compiler compiler = new Compiler();
1✔
48

49
    @SuppressWarnings("unchecked")
50
    public Class<Object> polymorphicSchemaType(Class<?> schemaType) {
51
        return ofNullable(schemaType.getAnnotation(SubType.class)).map(subType -> {
1✔
52
            Object subTypeProperty = actual.property(compiler.toChainNodes(subType.property())).value();
1✔
53
            return (Class<Object>) Stream.of(subType.types()).filter(t -> t.value().equals(subTypeProperty))
1✔
54
                    .map(SubType.Type::type).findFirst().orElseThrow(() -> new DALRuntimeException(
1✔
55
                            format("Cannot guess sub type through property type value[%s]", subTypeProperty)));
1✔
56
        }).orElse((Class<Object>) schemaType);
1✔
57
    }
58

59
    public IllegalStateException invalidGenericType() {
60
        return new IllegalStateException(format("%s should specify generic type", property));
1✔
61
    }
62

63
    public boolean convertAble(BeanClass<?> type, String inspect) {
64
        if (isNull())
1✔
UNCOV
65
            return Verification.errorLog("Can not convert null field `%s` to %s, " +
×
66
                    "use @AllowNull to verify nullable field", property, inspect);
67
        try {
68
            actual.convert(type.getType());
1✔
69
            return true;
1✔
70
        } catch (Exception ignore) {
1✔
71
            return Verification.errorLog("Can not convert field `%s` (%s: %s) to %s", property,
1✔
72
                    getClassName(actual.value()), actual.value(), inspect);
1✔
73
        }
74
    }
75

76
    public boolean verifyValue(Value<Object> value, BeanClass<?> type) {
77
        if (value.verify(value.convertAs(actual, type))) return true;
1✔
UNCOV
78
        return Verification.errorLog(value.errorMessage(property, actual.value()));
×
79
    }
80

81
    public Stream<?> fieldNames() {
82
        return actual.fieldNames().stream();
1✔
83
    }
84

85
    public Stream<Actual> subElements() {
86
        return actual.list().wraps().stream().map(data -> new Actual(property + "[" + data.index() + "]", data.value()));
1✔
87
    }
88

89
    public boolean verifyFormatter(Formatter<Object, Object> formatter) {
90
        return formatter.isValid(actual.value())
1✔
91
                || Verification.errorLog("Expected field `%s` to be formatter `%s`\nActual: %s", property,
1✔
92
                formatter.getFormatterName(), actual.dump());
1✔
93
    }
94

95
    boolean verifySize(Function<Actual, Stream<?>> actualStream, int expectSize) {
96
        return actualStream.apply(this).count() == expectSize
1✔
97
                || Verification.errorLog("Expected field `%s` to be size <%d>, but was size <%d>",
1✔
98
                property, expectSize, actualStream.apply(this).count());
1✔
99
    }
100

101
    boolean moreExpectSize(int size) {
102
        return Verification.errorLog("Collection Field `%s` size was only <%d>, expected too more",
1✔
103
                property, size);
1✔
104
    }
105

106
    public boolean lessExpectSize(int size) {
UNCOV
107
        return Verification.errorLog("Expected collection field `%s` to be size <%d>, but too many elements", property, size);
×
108
    }
109

110
    boolean verifyType(Type<Object> expect) {
111
        if (expect.verify(actual.value())) return true;
1✔
UNCOV
112
        return Verification.errorLog(expect.errorMessage(property, actual.value()));
×
113
    }
114

115
    boolean inInstanceOf(BeanClass<?> type) {
116
        return type.isInstance(actual.value()) ||
1✔
117
                Verification.errorLog(String.format("Expected field `%s` to be %s\nActual: %s", property,
1✔
118
                        type.getName(), actual.dump()));
1✔
119
    }
120

121
    public boolean equalsExpect(Object expect, DALRuntimeContext runtimeContext) {
122
        return Objects.equals(expect, actual.value()) ||
1✔
123
                Verification.errorLog(format("Expected field `%s` to be %s\nActual: %s", property,
1✔
124
                        runtimeContext.data(expect).dump(), actual.dump()));
1✔
125
    }
126

127
    public void verifySchema(Schema expect) {
128
        try {
129
            expect.verify(actual);
1✔
130
        } catch (Throwable throwable) {
1✔
UNCOV
131
            Verification.errorLog(throwable.getMessage());
×
132
        }
1✔
133
    }
1✔
134
}
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