Sample

Schnappinger/junit4/org.junit.internal.runners.statements.ExpectException

Human rating uses the original dataset scale.

Human3.96
Lines36

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
55.9Δ 26.0
Scalabrino0.6650–1; higher is more readable
30.8Δ 51.0
Dorn0.5830–1; higher is more readable
65.3Δ 16.5
Mi0.6380–1; higher is more readable
71.0Δ 10.9
LLOC16Logical lines; fewer is more readable
64.9Δ 17.0
DeepSeek V4 Pro160–20; mean of three runs
47.4Δ 34.5
GPT-6.1 Sol180–20; mean of three runs
73.8Δ 8.1
BTTF0.5890–1; higher is more readable
56.1Δ 25.7
Human3.961–4; original rating
81.8

Views

Source code

package org.junit.internal.runners.statements; import org.junit.internal.AssumptionViolatedException; import org.junit.runners.model.Statement; public class ExpectException extends Statement { private Statement fNext; private final Class<? extends Throwable> fExpected; public ExpectException(Statement next, Class<? extends Throwable> expected) { fNext = next; fExpected = expected; } @Override public void evaluate() throws Exception { boolean complete = false; try { fNext.evaluate(); complete = true; } catch (AssumptionViolatedException e) { throw e; } catch (Throwable e) { if (!fExpected.isAssignableFrom(e.getClass())) { String message = "Unexpected exception, expected<" + fExpected.getName() + "> but was<" + e.getClass().getName() + ">"; throw new Exception(message, e); } } if (complete) { throw new AssertionError("Expected exception: " + fExpected.getName()); } } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.1122.309−37.036
Source linesThe number of non-empty source lines.36+14.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.3−6.45

Intercept 8.87 + feature contributions = -20.216 (log-odds).
Score = sigmoid(-20.216) = 0.

Score0.665

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Indentation frequencyHow rapidly indentation changes from line to line.36+0.508
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.36−0.238
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.80.972+0.236
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.087+0.092
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.34.671+0.075

Intercept 0.07 + feature contributions = 0.335 (log-odds).
Score = sigmoid(0.335) = 0.583.

Score0.638
Score16
Run 1

The code is well-structured with clear separation of concerns, a single-purpose class, and a logical evaluate() method. Nesting is minimal (one try/catch block) and action granularity is good, with most lines performing one task. The intent is clear: expect a specific exception or fail. However, the reading flow is slightly disrupted by the boolean 'complete' flag and the post-try conditional, which forces the reader to track state across the method. Field names like 'fNext' and 'fExpected' are outdated and reduce clarity compared to modern Java conventions. The code is concise but could be improved with a more natural control flow (e.g., using a local variable to capture the outcome). Overall, it is readable but not exemplary.

Run 2

The code is well-structured and readable. It has a clear purpose: verify that an expected exception is thrown. The class is focused with a single responsibility, and the evaluate method follows a straightforward try-catch flow with minimal nesting. Variable names like fNext and fExpected are slightly archaic (Hungarian notation prefix 'f' for field), but they are used consistently. The logic is easy to follow: run the next statement, if it completes without exception, fail; if an unexpected exception is thrown, wrap it; if the expected exception type is thrown, silently succeed. The message construction is somewhat verbose but clear. Overall, the code is concise and maintains good reading flow, though modern Java conventions would drop the 'f' prefix and use final fields with 'next' and 'expected'.

Run 3

The code is generally clear and well-structured. It follows a logical try-catch flow and keeps nesting shallow. Each action is on its own line, which improves readability. The intent is mostly clear: fail if no exception is thrown or if the wrong type is thrown, and rethrow assumption violations. However, the boolean flag 'complete' adds slight ambiguity and control-flow complexity. Variable names like fNext and fExpected follow an old-style Hungarian notation that reduces clarity. The use of a generic Exception with a detailed message is reasonable but could be more specific. Overall, the code is readable and concise but could improve with clearer variable names and a more direct way to express the post-try assertion.

Run 1

Code Structure: Fields, constructor, and evaluation logic are logically organized. Nesting: Shallow try/catch blocks with one nested conditional keep complexity low. Clarity of intent: The class clearly verifies an expected exception while preserving assumption violations; however, the complete flag and f-prefixed field names require minor interpretation. Code length: Concise, with no unnecessary duplication. Action granularity: Each statement performs a single action; multiline string concatenation remains readable. Reading flow: Execution proceeds naturally from running the statement to checking exception compatibility and detecting a missing exception, though the flag-based final check adds slight mental overhead.

Run 2

Code Structure: The class cleanly separates initialization from exception-checking behavior. Nesting: A single conditional inside a catch block keeps nesting shallow. Clarity of intent: The class name, expected exception type, and error messages clearly communicate its purpose; prefixed field names and the indirect 'complete' flag slightly reduce clarity. Code length: Compact, with no unnecessary repetition. Action granularity: Each statement performs one distinct action, and multiline message construction remains easy to follow. Reading flow: Execution proceeds naturally from running the wrapped statement to handling exceptions and detecting a missing exception, though understanding the final check requires tracking the flag through the try/catch.

Run 3

Code Structure: The class is logically organized, with fields, constructor, and a focused evaluation method. Nesting: Shallow try/catch blocks and a single nested conditional are easy to follow. Clarity of intent: The class name and expected exception type clearly communicate the purpose, though the f-prefixed fields and 'complete' flag are slightly less descriptive. Code length: Compact without unnecessary repetition. Action granularity: Each statement performs one clear action; multiline string concatenation remains readable. Reading flow: Execution, exception handling, and the missing-exception assertion follow naturally. The completion flag requires a little mental tracking, but overall readability is high.