Sample

Schnappinger/junit4/org.junit.Assume

Human rating uses the original dataset scale.

Human3.96
Lines157

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett0.9990–1; higher is more readable
91.6Δ 14.6
Scalabrino0.9250–1; higher is more readable
94.9Δ 17.8
Dorn0.2660–1; higher is more readable
45.5Δ 31.5
Mi0.1350–1; higher is more readable
11.9Δ 65.2
LLOC21Logical lines; fewer is more readable
58.4Δ 18.6
DeepSeek V4 Pro17.330–20; mean of three runs
73.9Δ 3.1
GPT-6.1 Sol180–20; mean of three runs
73.8Δ 3.3
BTTF0.6870–1; higher is more readable
77.6Δ 0.5
Human3.961–4; original rating
77.1

Views

Source code

package org.junit; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import org.hamcrest.Matcher; /** * A set of methods useful for stating assumptions about the conditions in which a test is meaningful. * A failed assumption does not mean the code is broken, but that the test provides no useful information. * The default JUnit runner treats tests with failing assumptions as ignored. Custom runners may behave differently. * * For example: * <pre> * // only provides information if database is reachable. * &#064;Test public void calculateTotalSalary() { * DBConnection dbc = Database.connect(); * assumeNotNull(dbc); * // ... * } * </pre> * These methods can be used directly: <code>Assume.assumeTrue(...)</code>, however, they * read better if they are referenced through static import:<br/> * <pre> * import static org.junit.Assume.*; * ... * assumeTrue(...); * </pre> * * @since 4.4 */ public class Assume { /** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. */ public static void assumeTrue(boolean b) { assumeThat(b, is(true)); } /** * The inverse of {@link #assumeTrue(boolean)}. */ public static void assumeFalse(boolean b) { assumeTrue(!b); } /** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. * * @param b If <code>false</code>, the method will attempt to stop the test and ignore it by * throwing {@link AssumptionViolatedException}. * @param message A message to pass to {@link AssumptionViolatedException}. */ public static void assumeTrue(String message, boolean b) { if (!b) throw new AssumptionViolatedException(message); } /** * The inverse of {@link #assumeTrue(String, boolean)}. */ public static void assumeFalse(String message, boolean b) { assumeTrue(message, !b); } /** * If called with one or more null elements in <code>objects</code>, the test will halt and be ignored. */ public static void assumeNotNull(Object... objects) { assumeThat(asList(objects), everyItem(notNullValue())); } /** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(actual, matcher); } } /** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(String message, T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(message, actual, matcher); } } /** * Use to assume that an operation completes normally. If {@code e} is non-null, the test will halt and be ignored. * * For example: * <pre> * \@Test public void parseDataFile() { * DataFile file; * try { * file = DataFile.open("sampledata.txt"); * } catch (IOException e) { * // stop test and ignore if data can't be opened * assumeNoException(e); * } * // ... * } * </pre> * * @param e if non-null, the offending exception */ public static void assumeNoException(Throwable e) { assumeThat(e, nullValue()); } /** * Attempts to halt the test and ignore it if Throwable <code>e</code> is * not <code>null</code>. Similar to {@link #assumeNoException(Throwable)}, * but provides an additional message that can explain the details * concerning the assumption. * * @param e if non-null, the offending exception * @param message Additional message to pass to {@link AssumptionViolatedException}. * @see #assumeNoException(Throwable) */ public static void assumeNoException(String message, Throwable e) { assumeThat(message, e, nullValue()); } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Source linesThe number of non-empty source lines.157+62.8
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.1738.634−57.375
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.622−6.933

Intercept 8.87 + feature contributions = 7.362 (log-odds).
Score = sigmoid(7.362) = 0.999.

Score0.925

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.156−4.487
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.140.975−2.306
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.156.923+1.784
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.140.981+1.47
Indentation frequencyHow rapidly indentation changes from line to line.61+1.373
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.027+0.681
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = -1.017 (log-odds).
Score = sigmoid(-1.017) = 0.266.

Score0.135
Score21
Run 1

The code is highly readable with a clear, logical structure. It begins with focused static imports, followed by comprehensive Javadoc that explains intent and usage examples. The class is organized into small, single-purpose methods, resulting in flat code with minimal nesting. Method names and parameters clearly express their actions, and each non-doc line generally performs one action. The reading flow is natural, from general assumptions to more specific variants (e.g., with messages or no exceptions). Minor limitations include some repetitive Javadoc and slightly verbose documentation, but these do not detract from overall clarity.

Run 2

The code is well-structured, with clear Javadoc explanations and logical organization. Methods are short, focused, and delegate cleanly to core logic (e.g., assumeThat). There is minimal nesting—only one level in condition checks—and each method performs a single action, improving granularity. Static imports are used thoughtfully to enhance readability, and the reading flow is natural, following a consistent pattern from simple boolean assumptions to matcher-based and exception-based assumptions. Minor deductions are for some repetitive Javadoc examples and the slightly dense import block, but overall clarity of intent is high.

Run 3

The code is highly readable. Structure is logical: class-level Javadoc explains purpose, methods are grouped by functionality, and each public method has concise documentation. Nesting is minimal, with only single-level conditionals. Intent is clear due to descriptive method names (assumeTrue, assumeFalse, assumeNotNull, assumeNoException) and consistent delegation to assumeThat. Code length is appropriate—no unnecessary verbosity or duplication. Action granularity is mostly one action per line, though some single-line if-throw statements slightly reduce readability. Reading flow is natural: overloaded methods follow a logical progression, and imports are organized. Minor deductions include some Javadoc examples being verbose and single-line conditional throws, but overall the code is well-organized and easy to understand.

Run 1

Code Structure: Methods are logically grouped by assumption type, with related overloads adjacent and shared behavior delegated to helper methods. Nesting: Very shallow; conditionals contain only a single throw. Clarity of intent: Descriptive method names and extensive Javadoc make the API purpose clear, though parameter names such as b and e are terse. Code length: Implementations are concise, but duplicated documentation for assumeThat overloads adds unnecessary length. Action granularity: Almost every line performs one action; the inline if-and-throw statement is a minor formatting inconsistency. Reading flow: Consistent formatting and predictable method organization support natural reading, with small documentation issues such as malformed example markup and a missing message parameter description slightly reducing polish.

Run 2

Code Structure: Methods are logically grouped by assumption type, with overloads adjacent and shared behavior delegated to helper methods. Nesting: Control flow is flat, with at most one conditional level. Clarity of intent: Descriptive method names and extensive documentation clearly explain behavior; parameter names such as b and e are less descriptive. Code length: Implementations are concise, although duplicated Javadoc for assumeThat overloads adds unnecessary length. Action granularity: Most lines contain a single action; the inline if-and-throw statement slightly reduces consistency and scanability. Reading flow: Consistent formatting, static imports, and predictable method organization make the class easy to follow. Minor documentation formatting defects and inconsistent conditional formatting prevent a perfect score.

Run 3

Code Structure: Well-organized utility class with related methods and overloads grouped together; delegation avoids tangled logic. Nesting: Nearly flat, with only simple conditional checks. Clarity of intent: Descriptive method names and extensive documentation clearly explain assumptions and failure behavior, although parameter names b and e are terse. Code length: Implementations are concise, but duplicated assumeThat documentation and lengthy examples add unnecessary bulk. Action granularity: Most statements perform one action per line; the inline if-and-throw statement is a minor inconsistency. Reading flow: Consistent formatting, static imports, and predictable method grouping support natural reading, slightly interrupted by repetitive documentation and minor documentation formatting defects.