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

hazendaz / jmockit1 / 422

30 Oct 2025 09:23PM UTC coverage: 72.22% (+0.02%) from 72.198%
422

push

github

hazendaz
Combine catches

5674 of 8356 branches covered (67.9%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

52 existing lines in 8 files now uncovered.

11929 of 16018 relevant lines covered (74.47%)

0.74 hits per line

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

38.24
/main/src/main/java/mockit/internal/reflection/MockInvocationHandler.java
1
/*
2
 * Copyright (c) 2006 JMockit developers
3
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
4
 */
5
package mockit.internal.reflection;
6

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

10
import java.lang.annotation.Annotation;
11
import java.lang.reflect.Constructor;
12
import java.lang.reflect.InvocationHandler;
13
import java.lang.reflect.Method;
14

15
import mockit.internal.util.DefaultValues;
16
import mockit.internal.util.ObjectMethods;
17

18
/**
19
 * Handles invocations to all kinds of mock implementations created for interfaces and annotation types through any of
20
 * the mocking APIs.
21
 * <p>
22
 * The <code>java.lang.Object</code> methods <code>equals</code>, <code>hashCode</code>, and <code>toString</code> are
23
 * handled in a meaningful way, returning a value that makes sense for the proxy instance. The special
24
 * {@linkplain Annotation} contracts for these three methods is <em>not</em> observed, though, since it would require
25
 * making dynamic calls to the mocked annotation attributes.
26
 * <p>
27
 * Any other method invocation is handled by simply returning the default value according to the method's return type
28
 * (as defined in {@linkplain DefaultValues}).
29
 */
30
public final class MockInvocationHandler implements InvocationHandler {
1✔
31
    public static final InvocationHandler INSTANCE = new MockInvocationHandler();
1✔
32
    private static final Class<?>[] CONSTRUCTOR_PARAMETERS_FOR_PROXY_CLASS = { InvocationHandler.class };
1✔
33

34
    @NonNull
35
    public static Object newMockedInstance(@NonNull Class<?> proxyClass) {
36
        Constructor<?> publicConstructor;
37
        try {
38
            publicConstructor = proxyClass.getConstructor(CONSTRUCTOR_PARAMETERS_FOR_PROXY_CLASS);
1✔
39
        } catch (NoSuchMethodException e) {
×
40
            throw new RuntimeException(e);
×
41
        }
1✔
42

43
        return ConstructorReflection.invokeAccessible(publicConstructor, INSTANCE);
1✔
44
    }
45

46
    @Nullable
47
    @Override
48
    public Object invoke(@NonNull Object proxy, @NonNull Method method, @Nullable Object[] args) {
49
        Class<?> declaringClass = method.getDeclaringClass();
1✔
50
        String methodName = method.getName();
1✔
51

52
        if (declaringClass == Object.class) {
1!
53
            if ("equals".equals(methodName)) {
×
54
                return args != null && args.length > 0 && proxy == args[0];
×
55
            }
UNCOV
56
            if ("hashCode".equals(methodName)) {
×
57
                return System.identityHashCode(proxy);
×
58
            }
59
            // "toString"
UNCOV
60
            return ObjectMethods.objectIdentity(proxy);
×
61
        }
62

63
        if (declaringClass == Annotation.class) {
1!
64
            return proxy.getClass().getInterfaces()[0];
1✔
65
        }
66

UNCOV
67
        Class<?> retType = method.getReturnType();
×
68
        return DefaultValues.computeForType(retType);
×
69
    }
70
}
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