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

leeonky / test-charm-java / 227

21 Apr 2025 03:32PM UTC coverage: 71.06% (-3.0%) from 74.052%
227

push

circleci

leeonky
Refactor UI test

6 of 15 new or added lines in 5 files covered. (40.0%)

42 existing lines in 11 files now uncovered.

6858 of 9651 relevant lines covered (71.06%)

0.71 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.runtime.SchemaAssertionFailure;
11
import com.github.leeonky.dal.type.Schema;
12
import com.github.leeonky.dal.type.SubType;
13
import com.github.leeonky.util.BeanClass;
14

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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