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

leeonky / test-charm-java / 150

07 Mar 2025 12:58AM UTC coverage: 74.287% (-0.08%) from 74.367%
150

push

circleci

leeonky
Try to fix ci

7919 of 10660 relevant lines covered (74.29%)

0.74 hits per line

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

75.0
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/InstanceCurryingMethod.java
1
package com.github.leeonky.dal.runtime;
2

3
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
4
import com.github.leeonky.util.Converter;
5

6
import java.lang.reflect.Method;
7
import java.lang.reflect.Parameter;
8
import java.util.*;
9
import java.util.function.BiFunction;
10
import java.util.function.Predicate;
11

12
import static com.github.leeonky.util.Suppressor.get;
13
import static java.lang.String.format;
14
import static java.util.Collections.emptySet;
15
import static java.util.stream.Collectors.joining;
16
import static java.util.stream.Collectors.toList;
17

18
public class InstanceCurryingMethod implements CurryingMethod {
19
    protected final Object instance;
20
    protected final Method method;
21
    protected final Converter converter;
22
    protected final DALRuntimeContext context;
23
    protected final List<ParameterValue> parameterValues = new ArrayList<>();
1✔
24

25
    protected InstanceCurryingMethod(Object instance, Method method, Converter converter, DALRuntimeContext context) {
1✔
26
        this.method = method;
1✔
27
        this.instance = instance;
1✔
28
        this.converter = converter;
1✔
29
        this.context = context;
1✔
30
    }
1✔
31

32
    @Override
33
    public InstanceCurryingMethod call(Object arg) {
34
        InstanceCurryingMethod curryingMethod = clone();
1✔
35
        curryingMethod.parameterValues.addAll(parameterValues);
1✔
36
        curryingMethod.parameterValues.add(new ParameterValue(currentPositionParameter(), arg));
1✔
37
        return curryingMethod;
1✔
38
    }
39

40
    private Parameter currentPositionParameter() {
41
        return method.getParameters()[parameterValues.size() + parameterOffset()];
1✔
42
    }
43

44
    protected int parameterOffset() {
45
        return 0;
1✔
46
    }
47

48
    @Override
49
    protected InstanceCurryingMethod clone() {
50
        return new InstanceCurryingMethod(instance, method, converter, context);
1✔
51
    }
52

53
    private String parameterInfo() {
54
        List<String> parameters = Arrays.stream(method.getParameters()).map(Parameter::toString).collect(toList());
×
55
        int argPosition = parameterValues.size() + parameterOffset();
×
56
        if (!parameters.isEmpty())
×
57
            parameters.set(argPosition, "> " + parameters.get(argPosition));
×
58
        return parameters.stream().collect(joining(",\n", format("%s.%s(\n", method.getDeclaringClass().getName(),
×
59
                method.getName()), "\n)"));
×
60
    }
61

62
    public boolean allParamsSameType() {
63
        return testParameterTypes(ParameterValue::isSameType);
1✔
64
    }
65

66
    private boolean testParameterTypes(Predicate<ParameterValue> checking) {
67
        return isArgCountEnough() && parameterValues.stream().allMatch(checking);
1✔
68
    }
69

70
    private boolean isArgCountEnough() {
71
        return method.getParameterCount() - parameterOffset() == parameterValues.size();
1✔
72
    }
73

74
    public boolean allParamsBaseType() {
75
        return testParameterTypes(ParameterValue::isSuperType);
1✔
76
    }
77

78
    public boolean allParamsConvertible() {
79
        return testParameterTypes(parameterValue -> parameterValue.isConvertibleType(converter));
1✔
80
    }
81

82
    @Override
83
    public Object resolve() {
84
        return get(() -> method.invoke(instance, parameterValues.stream().map(parameterValue ->
1✔
85
                parameterValue.getArg(converter)).collect(toList()).toArray()));
1✔
86
    }
87

88
    @Override
89
    public Set<Object> fetchArgRange() {
90
        BiFunction<Object, List<Object>, List<Object>> rangeFactory = context.fetchCurryingMethodArgRange(method);
1✔
91
        if (rangeFactory != null)
1✔
92
            return new LinkedHashSet<>(rangeFactory.apply(instance, parameterValues.stream()
1✔
93
                    .map(parameterValue -> parameterValue.getArg(converter)).collect(toList())));
1✔
94
        System.err.printf("No arg range for %s, give the range or use `:`%n", parameterInfo());
×
95
        return emptySet();
×
96
    }
97

98
    @Override
99
    public String toString() {
100
        return method.toString();
1✔
101
    }
102

103
    public boolean isSameInstanceType() {
104
        return true;
×
105
    }
106

107
    @Override
108
    public Object convertToArgType(Object obj) {
109
        return converter.convert(currentPositionParameter().getType(), obj);
1✔
110
    }
111
}
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