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

hazendaz / jmockit1 / 496

15 Nov 2025 05:33PM UTC coverage: 72.192% (-0.008%) from 72.2%
496

push

github

web-flow
Merge pull request #412 from hazendaz/renovate/major-spring-core

Update spring core to v7 (major)

5677 of 8360 branches covered (67.91%)

Branch coverage included in aggregate %.

11922 of 16018 relevant lines covered (74.43%)

0.74 hits per line

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

90.54
/main/src/main/java/mockit/internal/injection/InterfaceResolution.java
1
/*
2
 * MIT License
3
 * Copyright (c) 2006-2025 JMockit developers
4
 * See LICENSE file for full license text.
5
 */
6
package mockit.internal.injection;
7

8
import static mockit.internal.reflection.MethodReflection.invoke;
9
import static mockit.internal.util.Utilities.getClassType;
10

11
import edu.umd.cs.findbugs.annotations.NonNull;
12
import edu.umd.cs.findbugs.annotations.Nullable;
13

14
import java.lang.reflect.Method;
15
import java.lang.reflect.ParameterizedType;
16
import java.lang.reflect.Type;
17
import java.lang.reflect.WildcardType;
18
import java.util.Map.Entry;
19
import java.util.NavigableMap;
20
import java.util.TreeMap;
21

22
final class InterfaceResolution {
23
    @NonNull
24
    private final NavigableMap<ParameterizedType, Method> interfaceResolutionMethods;
25

26
    InterfaceResolution() {
1✔
27
        interfaceResolutionMethods = new TreeMap<>((t1, t2) -> {
1✔
28
            if (t1 == t2) {
1✔
29
                return 0;
1✔
30
            }
31

32
            Type targetType1 = t1.getActualTypeArguments()[0];
1✔
33
            Type targetType2 = t2.getActualTypeArguments()[0];
1✔
34

35
            if (targetType1 == targetType2) {
1!
36
                return 0;
×
37
            }
38

39
            if (targetType1 instanceof WildcardType) {
1!
40
                if (targetType2 instanceof WildcardType) {
1✔
41
                    return compareTypesFromResolutionMethods((WildcardType) targetType1, (WildcardType) targetType2);
1✔
42
                }
43

44
                return 1;
1✔
45
            }
46

47
            return -1;
×
48
        });
49
    }
1✔
50

51
    private static int compareTypesFromResolutionMethods(@NonNull WildcardType type1, @NonNull WildcardType type2) {
52
        Type upperBound1 = type1.getUpperBounds()[0];
1✔
53
        Class<?> classOfUpperBound1 = getClassType(upperBound1);
1✔
54

55
        Type upperBound2 = type2.getUpperBounds()[0];
1✔
56
        Class<?> classOfUpperBound2 = getClassType(upperBound2);
1✔
57

58
        if (classOfUpperBound1.isAssignableFrom(classOfUpperBound2)) {
1✔
59
            return 1;
1✔
60
        }
61

62
        if (classOfUpperBound2.isAssignableFrom(classOfUpperBound1)) {
1!
63
            return -1;
×
64
        }
65

66
        return classOfUpperBound1.getName().compareTo(classOfUpperBound2.getName());
1✔
67
    }
68

69
    boolean canResolveInterfaces() {
70
        return !interfaceResolutionMethods.isEmpty();
1!
71
    }
72

73
    void addInterfaceResolutionMethod(@NonNull ParameterizedType interfaceType, @NonNull Method resolutionMethod) {
74
        interfaceResolutionMethods.put(interfaceType, resolutionMethod);
1✔
75
    }
1✔
76

77
    @Nullable
78
    Class<?> resolveInterface(@NonNull Class<?> anInterface, @NonNull Object testClassInstance) {
79
        if (interfaceResolutionMethods.isEmpty()) {
1✔
80
            return null;
1✔
81
        }
82

83
        for (Entry<ParameterizedType, Method> typeAndMethod : interfaceResolutionMethods.entrySet()) {
1✔
84
            ParameterizedType acceptedType = typeAndMethod.getKey();
1✔
85
            Method method = typeAndMethod.getValue();
1✔
86
            Type targetType = acceptedType.getActualTypeArguments()[0];
1✔
87

88
            if (targetType == anInterface || targetType instanceof WildcardType
1✔
89
                    && satisfiesUpperBounds(anInterface, (WildcardType) targetType)) {
1✔
90
                Class<?> implementationClass = invoke(testClassInstance, method, anInterface);
1✔
91

92
                if (implementationClass != null) {
1✔
93
                    return implementationClass;
1✔
94
                }
95
            }
96
        }
1✔
97

98
        return null;
1✔
99
    }
100

101
    private static boolean satisfiesUpperBounds(@NonNull Class<?> interfaceType, @NonNull WildcardType targetType) {
102
        for (Type upperBound : targetType.getUpperBounds()) {
1✔
103
            Class<?> classOfUpperBound = getClassType(upperBound);
1✔
104

105
            if (!classOfUpperBound.isAssignableFrom(interfaceType)) {
1✔
106
                return false;
1✔
107
            }
108
        }
109

110
        return true;
1✔
111
    }
112
}
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