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

hazendaz / jmockit1 / 420

30 Oct 2025 05:17PM UTC coverage: 72.177% (-0.03%) from 72.206%
420

push

github

hazendaz
Use re-entrant lock

5681 of 8360 branches covered (67.95%)

Branch coverage included in aggregate %.

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

5 existing lines in 1 file now uncovered.

11941 of 16055 relevant lines covered (74.38%)

0.74 hits per line

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

0.0
/main/src/main/java/mockit/coverage/TestRun.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.coverage;
6

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

9
import java.util.concurrent.locks.ReentrantLock;
10

11
import mockit.coverage.data.CoverageData;
12
import mockit.coverage.data.FileCoverageData;
13
import mockit.coverage.lines.PerFileLineCoverage;
14
import mockit.coverage.testRedundancy.TestCoverage;
15

16
import org.checkerframework.checker.index.qual.NonNegative;
17

18
@SuppressWarnings("unused")
19
public final class TestRun {
NEW
20
    private static final ReentrantLock LOCK = new ReentrantLock();
×
21
    private static boolean terminated;
22

23
    private TestRun() {
24
    }
25

26
    public static void lineExecuted(@NonNegative int fileIndex, @NonNegative int line) {
27
        if (terminated) {
×
28
            return;
×
29
        }
30

NEW
31
        LOCK.lock();
×
32
        try {
33
            CoverageData coverageData = CoverageData.instance();
×
34
            PerFileLineCoverage fileData = coverageData.getFileData(fileIndex).lineCoverageInfo;
×
35
            CallPoint callPoint = null;
×
36

37
            if (coverageData.isWithCallPoints() && fileData.acceptsAdditionalCallPoints(line)) {
×
38
                callPoint = CallPoint.create(new Throwable());
×
39
            }
40

41
            int previousExecutionCount = fileData.registerExecution(line, callPoint);
×
42
            recordNewLineOrSegmentAsCoveredIfApplicable(previousExecutionCount);
×
43
        } finally {
NEW
44
            LOCK.unlock();
×
45
        }
46
    }
×
47

48
    private static void recordNewLineOrSegmentAsCoveredIfApplicable(@NonNegative int previousExecutionCount) {
49
        TestCoverage testCoverage = TestCoverage.INSTANCE;
×
50

51
        if (testCoverage != null) {
×
52
            testCoverage.recordNewItemCoveredByTestIfApplicable(previousExecutionCount);
×
53
        }
54
    }
×
55

56
    public static void branchExecuted(@NonNegative int fileIndex, @NonNegative int line, @NonNegative int branchIndex) {
57
        if (terminated) {
×
58
            return;
×
59
        }
60

NEW
61
        LOCK.lock();
×
62
        try {
63
            CoverageData coverageData = CoverageData.instance();
×
64
            PerFileLineCoverage fileData = coverageData.getFileData(fileIndex).lineCoverageInfo;
×
65

66
            if (fileData.hasValidBranch(line, branchIndex)) {
×
67
                CallPoint callPoint = null;
×
68

69
                if (coverageData.isWithCallPoints() && fileData.acceptsAdditionalCallPoints(line, branchIndex)) {
×
70
                    callPoint = CallPoint.create(new Throwable());
×
71
                }
72

73
                int previousExecutionCount = fileData.registerExecution(line, branchIndex, callPoint);
×
74
                recordNewLineOrSegmentAsCoveredIfApplicable(previousExecutionCount);
×
75
            }
76
        } finally {
NEW
77
            LOCK.unlock();
×
78
        }
79
    }
×
80

81
    public static void fieldAssigned(@NonNull String file, @NonNull String classAndFieldNames) {
82
        if (terminated) {
×
83
            return;
×
84
        }
85

NEW
86
        LOCK.lock();
×
87
        try {
88
            CoverageData coverageData = CoverageData.instance();
×
89
            FileCoverageData fileData = coverageData.getFileData(file);
×
90
            fileData.dataCoverageInfo.registerAssignmentToStaticField(classAndFieldNames);
×
91
        } finally {
NEW
92
            LOCK.unlock();
×
93
        }
94
    }
×
95

96
    public static void fieldRead(@NonNull String file, @NonNull String classAndFieldNames) {
97
        if (terminated) {
×
98
            return;
×
99
        }
100

NEW
101
        LOCK.lock();
×
102
        try {
103
            CoverageData coverageData = CoverageData.instance();
×
104
            FileCoverageData fileData = coverageData.getFileData(file);
×
105
            fileData.dataCoverageInfo.registerReadOfStaticField(classAndFieldNames);
×
106
        } finally {
NEW
107
            LOCK.unlock();
×
108
        }
109
    }
×
110

111
    public static void fieldAssigned(@NonNull Object instance, @NonNull String file,
112
            @NonNull String classAndFieldNames) {
113
        if (terminated) {
×
114
            return;
×
115
        }
116

NEW
117
        LOCK.lock();
×
118
        try {
119
            CoverageData coverageData = CoverageData.instance();
×
120
            FileCoverageData fileData = coverageData.getFileData(file);
×
121
            fileData.dataCoverageInfo.registerAssignmentToInstanceField(instance, classAndFieldNames);
×
122
        } finally {
NEW
123
            LOCK.unlock();
×
124
        }
125
    }
×
126

127
    public static void fieldRead(@NonNull Object instance, @NonNull String file, @NonNull String classAndFieldNames) {
128
        if (terminated) {
×
129
            return;
×
130
        }
131

NEW
132
        LOCK.lock();
×
133
        try {
134
            CoverageData coverageData = CoverageData.instance();
×
135
            FileCoverageData fileData = coverageData.getFileData(file);
×
136
            fileData.dataCoverageInfo.registerReadOfInstanceField(instance, classAndFieldNames);
×
137
        } finally {
NEW
138
            LOCK.unlock();
×
139
        }
140
    }
×
141

142
    static void terminate() {
143
        terminated = true;
×
144
    }
×
145

146
    public static boolean isTerminated() {
147
        return terminated;
×
148
    }
149
}
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