• 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

64.29
/main/src/main/java/mockit/internal/util/Utilities.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.util;
7

8
import edu.umd.cs.findbugs.annotations.NonNull;
9
import edu.umd.cs.findbugs.annotations.Nullable;
10

11
import java.lang.annotation.Annotation;
12
import java.lang.reflect.AccessibleObject;
13
import java.lang.reflect.GenericArrayType;
14
import java.lang.reflect.Method;
15
import java.lang.reflect.ParameterizedType;
16
import java.lang.reflect.Type;
17
import java.lang.reflect.TypeVariable;
18
import java.lang.reflect.WildcardType;
19
import java.net.URLDecoder;
20
import java.nio.charset.StandardCharsets;
21
import java.security.CodeSource;
22
import java.util.List;
23

24
/**
25
 * Miscellaneous utility constants and methods.
26
 */
27
public final class Utilities {
28
    @NonNull
29
    public static final Object[] NO_ARGS = {};
1✔
30
    public static final boolean JAVA8;
31
    public static final boolean HOTSPOT_VM;
32

33
    static {
34
        float javaVersion = Float.parseFloat(System.getProperty("java.specification.version"));
1✔
35
        JAVA8 = javaVersion >= 1.8F;
1!
36
        String vmName = System.getProperty("java.vm.name");
1✔
37
        HOTSPOT_VM = vmName.contains("HotSpot") || vmName.contains("OpenJDK");
1!
38
    }
1✔
39

40
    private Utilities() {
41
    }
42

43
    public static void ensureThatMemberIsAccessible(@NonNull AccessibleObject classMember) {
44
        // noinspection deprecation
45
        if (!classMember.isAccessible()) {
1✔
46
            classMember.setAccessible(true);
1✔
47
        }
48
    }
1✔
49

50
    public static Method getAnnotatedMethod(Class<?> cls, Class<? extends Annotation> annotation) {
51
        for (Method method : cls.getMethods()) {
×
52
            if (method.getAnnotation(annotation) != null) {
×
53
                return method;
×
54
            }
55
        }
56
        return null;
×
57
    }
58

59
    public static Method getAnnotatedDeclaredMethod(Class<?> cls, Class<? extends Annotation> annotation) {
60
        for (Method method : cls.getDeclaredMethods()) {
1✔
61
            if (method.getAnnotation(annotation) != null) {
1✔
62
                return method;
1✔
63
            }
64
        }
65
        return null;
1✔
66
    }
67

68
    @NonNull
69
    public static Class<?> getClassType(@NonNull Type declaredType) {
70
        while (true) {
71
            if (declaredType instanceof Class<?>) {
1✔
72
                return (Class<?>) declaredType;
1✔
73
            }
74

75
            if (declaredType instanceof ParameterizedType) {
1✔
76
                return (Class<?>) ((ParameterizedType) declaredType).getRawType();
1✔
77
            }
78

79
            if (declaredType instanceof GenericArrayType) {
1!
80
                declaredType = ((GenericArrayType) declaredType).getGenericComponentType();
×
81
                continue;
×
82
            }
83

84
            if (declaredType instanceof TypeVariable) {
1!
85
                declaredType = ((TypeVariable<?>) declaredType).getBounds()[0];
1✔
86
                continue;
1✔
87
            }
88

89
            if (declaredType instanceof WildcardType) {
×
90
                declaredType = ((WildcardType) declaredType).getUpperBounds()[0];
×
91
                continue;
×
92
            }
93

94
            throw new IllegalArgumentException("Type of unexpected kind: " + declaredType);
×
95
        }
96
    }
97

98
    public static boolean containsReference(@NonNull List<?> references, @Nullable Object toBeFound) {
99
        for (Object reference : references) {
1✔
100
            if (reference == toBeFound) {
1✔
101
                return true;
1✔
102
            }
103
        }
1✔
104

105
        return false;
1✔
106
    }
107

108
    @NonNull
109
    public static String getClassFileLocationPath(@NonNull Class<?> aClass) {
110
        CodeSource codeSource = aClass.getProtectionDomain().getCodeSource();
×
111
        return getClassFileLocationPath(codeSource);
×
112
    }
113

114
    @NonNull
115
    public static String getClassFileLocationPath(@NonNull CodeSource codeSource) {
116
        String locationPath = codeSource.getLocation().getPath();
×
117
        return URLDecoder.decode(locationPath, StandardCharsets.UTF_8);
×
118
    }
119
}
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