• 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

85.19
/main/src/main/java/mockit/internal/expectations/mocking/InstanceFactory.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.expectations.mocking;
7

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

11
import mockit.internal.util.StackTrace;
12

13
import org.objenesis.ObjenesisHelper;
14

15
/**
16
 * Factory for the creation of new mocked instances, and for obtaining/clearing the last instance created. There are
17
 * separate subclasses dedicated to mocked interfaces and mocked classes.
18
 */
19
public abstract class InstanceFactory {
20

21
    @NonNull
22
    private final Class<?> concreteClass;
23
    @Nullable
24
    Object lastInstance;
25

26
    InstanceFactory(@NonNull Class<?> concreteClass) {
1✔
27
        this.concreteClass = concreteClass;
1✔
28
    }
1✔
29

30
    @NonNull
31
    @SuppressWarnings("unchecked")
32
    final <T> T newUninitializedConcreteClassInstance() {
33
        try {
34
            return (T) ObjenesisHelper.newInstance(concreteClass);
1✔
35
        } catch (Exception e) {
×
36
            StackTrace.filterStackTrace(e);
×
37
            e.printStackTrace();
×
38
            throw e;
×
39
        }
40
    }
41

42
    @NonNull
43
    public abstract Object create();
44

45
    @Nullable
46
    public final Object getLastInstance() {
47
        return lastInstance;
1✔
48
    }
49

50
    public abstract void clearLastInstance();
51

52
    static final class InterfaceInstanceFactory extends InstanceFactory {
53
        @Nullable
54
        private Object emptyProxy;
55

56
        InterfaceInstanceFactory(@NonNull Object emptyProxy) {
57
            super(emptyProxy.getClass());
1✔
58
            this.emptyProxy = emptyProxy;
1✔
59
        }
1✔
60

61
        @NonNull
62
        @Override
63
        public Object create() {
64
            if (emptyProxy == null) {
1✔
65
                emptyProxy = newUninitializedConcreteClassInstance();
1✔
66
            }
67

68
            lastInstance = emptyProxy;
1✔
69
            return emptyProxy;
1✔
70
        }
71

72
        @Override
73
        public void clearLastInstance() {
74
            emptyProxy = null;
1✔
75
            lastInstance = null;
1✔
76
        }
1✔
77
    }
78

79
    static final class ClassInstanceFactory extends InstanceFactory {
80
        ClassInstanceFactory(@NonNull Class<?> concreteClass) {
81
            super(concreteClass);
1✔
82
        }
1✔
83

84
        @Override
85
        @NonNull
86
        public Object create() {
87
            lastInstance = newUninitializedConcreteClassInstance();
1✔
88
            return lastInstance;
1✔
89
        }
90

91
        @Override
92
        public void clearLastInstance() {
93
            lastInstance = null;
1✔
94
        }
1✔
95
    }
96
}
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