Dataset Viewer
Auto-converted to Parquet Duplicate
code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
55
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
static @Nullable String describeActualValue(String className, String methodName, int lineNumber) { InferenceClassVisitor visitor; try { // TODO(cpovirk): Verify that methodName is correct for constructors and static initializers. visitor = new InferenceClassVisitor(methodName); } catch (IllegalA...
<b>Call {@link Platform#inferDescription} rather than calling this directly.</b>
describeActualValue
java
google/truth
core/src/main/java/com/google/common/truth/ActualValueInference.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ActualValueInference.java
Apache-2.0
InferredType getElementTypeIfArrayOrThrow() { String descriptor = descriptor(); checkState(descriptor.charAt(0) == '[', "This type %s is not an array.", this); return create(descriptor.substring(1)); }
If the type is an array, return the element type. Otherwise, throw an exception.
getElementTypeIfArrayOrThrow
java
google/truth
core/src/main/java/com/google/common/truth/ActualValueInference.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ActualValueInference.java
Apache-2.0
public void isEqualToIgnoringScale(String expected) { compareValues(new BigDecimal(expected)); }
Checks that the actual value is equal to the value of the {@link BigDecimal} created from the expected string (i.e., checks that {@code actual.comparesTo(new BigDecimal(expected)) == 0}). <p><b>Note:</b> The scale of the BigDecimal is ignored. If you want to compare the values and the scales, use {@link #isEqualTo(Obj...
isEqualToIgnoringScale
java
google/truth
core/src/main/java/com/google/common/truth/BigDecimalSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/BigDecimalSubject.java
Apache-2.0
public void isEqualToIgnoringScale(long expected) { compareValues(new BigDecimal(expected)); }
Checks that the actual value is equal to the value of the {@link BigDecimal} created from the expected {@code long} (i.e., checks that {@code actual.comparesTo(new BigDecimal(expected)) == 0}). <p><b>Note:</b> The scale of the BigDecimal is ignored. If you want to compare the values and the scales, use {@link #isEqual...
isEqualToIgnoringScale
java
google/truth
core/src/main/java/com/google/common/truth/BigDecimalSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/BigDecimalSubject.java
Apache-2.0
@Override // To express more specific javadoc public void isEqualTo(@Nullable Object expected) { super.isEqualTo(expected); }
Checks that the actual value (including scale) is equal to the given {@link BigDecimal}. <p><b>Note:</b> If you only want to compare the values of the BigDecimals and not their scales, use {@link #isEqualToIgnoringScale(BigDecimal)} instead.
isEqualTo
java
google/truth
core/src/main/java/com/google/common/truth/BigDecimalSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/BigDecimalSubject.java
Apache-2.0
public void isTrue() { if (actual == null) { isEqualTo(true); // fails } else if (!actual) { failWithoutActual(simpleFact("expected to be true")); } }
Checks that the actual value is {@code true}.
isTrue
java
google/truth
core/src/main/java/com/google/common/truth/BooleanSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/BooleanSubject.java
Apache-2.0
public final void isIn(@Nullable Range<T> range) { T actual = actualAsT(); if (range == null) { failWithoutActual( simpleFact("could not perform range check because range is null"), fact("value to test for membership was", actual)); } else if (actual == null || !range.contains(actu...
Checks that the actual value is in {@code range}.
isIn
java
google/truth
core/src/main/java/com/google/common/truth/ComparableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ComparableSubject.java
Apache-2.0
public final void isNotIn(@Nullable Range<T> range) { T actual = actualAsT(); if (range == null) { failWithoutActual( simpleFact("could not perform range check because range is null"), fact("value to test for membership was", actual)); } else if (actual == null) { failWithAct...
Checks that the actual value is <i>not</i> in {@code range}.
isNotIn
java
google/truth
core/src/main/java/com/google/common/truth/ComparableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ComparableSubject.java
Apache-2.0
public void isEquivalentAccordingToCompareTo(@Nullable T expected) { Comparable<Object> actual = actualAsComparable(); if (expected == null) { failWithoutActual( simpleFact( "expected a value equivalent to null according to compareTo, but compareTo is" + " require...
Checks that the actual value is equivalent to {@code other} according to {@link Comparable#compareTo}, (i.e., checks that {@code a.comparesTo(b) == 0}). <p><b>Note:</b> Do not use this method for checking object equality. Instead, use {@link #isEqualTo(Object)}.
isEquivalentAccordingToCompareTo
java
google/truth
core/src/main/java/com/google/common/truth/ComparableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ComparableSubject.java
Apache-2.0
public final void isLessThan(@Nullable T other) { Comparable<Object> actual = actualAsComparable(); if (other == null) { failWithoutActual( simpleFact( "expected a value less than null according to compareTo, but compareTo is required to" + " reject null"), ...
Checks that the actual value is less than {@code other}. <p>To check that the actual value is less than <i>or equal to</i> {@code other}, use {@link #isAtMost}.
isLessThan
java
google/truth
core/src/main/java/com/google/common/truth/ComparableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ComparableSubject.java
Apache-2.0
static ImmutableList<Fact> makeComparisonFailureFacts( ImmutableList<Fact> headFacts, ImmutableList<Fact> tailFacts, String expected, String actual) { return concat(headFacts, formatExpectedAndActual(expected, actual), tailFacts); }
Contains part of the code responsible for creating a JUnit {@code ComparisonFailure} (if available) or a plain {@code AssertionError} (if not). <p>This particular class is responsible for the fallback when a platform offers {@code ComparisonFailure} but it is not available in a particular test environment. In practice...
makeComparisonFailureFacts
java
google/truth
core/src/main/java/com/google/common/truth/ComparisonFailures.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ComparisonFailures.java
Apache-2.0
public static <A extends @Nullable Object, E extends @Nullable Object> Correspondence<A, E> from( BinaryPredicate<A, E> predicate, String description) { return FromBinaryPredicate.create(predicate, description); }
Constructs a {@link Correspondence} that compares actual and expected elements using the given binary predicate. <p>The correspondence does not support formatting of diffs (see {@link #formatDiff}). You can add that behaviour by calling {@link Correspondence#formattingDiffsUsing}. <p>Note that, if the data you are as...
from
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
public static <A extends @Nullable Object, E extends @Nullable Object> Correspondence<A, E> transforming( Function<A, ? extends E> actualTransform, String description) { return Transforming.create(actualTransform, identity(), description); }
Constructs a {@link Correspondence} that compares elements by transforming the actual elements using the given function and testing for equality with the expected elements. If the transformed actual element (i.e. the output of the given function) is null, it will correspond to a null expected element. <p>The correspon...
transforming
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
public Correspondence<A, E> formattingDiffsUsing(DiffFormatter<? super A, ? super E> formatter) { return FormattingDiffs.create(this, formatter); }
Returns a new correspondence which is like this one, except that the given formatter may be used to format the difference between a pair of elements that do not correspond. <p>Note that, if you the data you are asserting about contains null actual or expected values, the formatter may be invoked with a null argument. ...
formattingDiffsUsing
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
void addCompareException( Class<?> callingClass, Exception exception, @Nullable Object actual, @Nullable Object expected) { if (firstCompareException == null) { truncateStackTrace(exception, callingClass); firstCompareException = StoredException.create(e...
Adds an exception that was thrown during a {@code compare} call. @param callingClass The class from which the {@code compare} method was called. When reporting failures, stack traces will be truncated above elements in this class. @param exception The exception encountered @param actual The {@code actual} argument...
addCompareException
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
void addActualKeyFunctionException( Class<?> callingClass, Exception exception, @Nullable Object actual) { if (firstPairingException == null) { truncateStackTrace(exception, callingClass); firstPairingException = StoredException.create(exception, "actualKeyFunction.apply", asLi...
Adds an exception that was thrown during an {@code apply} call on the function used to key actual elements. @param callingClass The class from which the {@code apply} method was called. When reporting failures, stack traces will be truncated above elements in this class. @param exception The exception encountered ...
addActualKeyFunctionException
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
void addExpectedKeyFunctionException( Class<?> callingClass, Exception exception, @Nullable Object expected) { if (firstPairingException == null) { truncateStackTrace(exception, callingClass); firstPairingException = StoredException.create(exception, "expectedKeyFunction.apply"...
Adds an exception that was thrown during an {@code apply} call on the function used to key expected elements. @param callingClass The class from which the {@code apply} method was called. When reporting failures, stack traces will be truncated above elements in this class. @param exception The exception encountere...
addExpectedKeyFunctionException
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
void addFormatDiffException( Class<?> callingClass, Exception exception, @Nullable Object actual, @Nullable Object expected) { if (firstFormatDiffException == null) { truncateStackTrace(exception, callingClass); firstFormatDiffException = StoredException...
Adds an exception that was thrown during a {@code formatDiff} call. @param callingClass The class from which the {@code formatDiff} method was called. When reporting failures, stack traces will be truncated above elements in this class. @param exception The exception encountered @param actual The {@code actual} ar...
addFormatDiffException
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
boolean hasCompareException() { return firstCompareException != null; }
Returns whether any exceptions thrown during {@code compare} calls were stored.
hasCompareException
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
ImmutableList<Fact> describeAsMainCause() { checkState(firstCompareException != null); // We won't do pairing or diff formatting unless a more meaningful failure was found, and if a // more meaningful failure was found then we shouldn't be using this method: checkState(firstPairingException == n...
Returns facts to use in a failure message when the exceptions from {@code compare} calls are the main cause of the failure. At least one exception thrown during a {@code compare} call must have been stored, and no exceptions from a {@code formatDiff} call. Assertions should use this when exceptions were thrown while co...
describeAsMainCause
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
final boolean safeCompare(A actual, E expected, ExceptionStore exceptions) { try { return compare(actual, expected); } catch (RuntimeException e) { exceptions.addCompareException(Correspondence.class, e, actual, expected); return false; } }
Invokes {@link #compare}, catching any exceptions. If the comparison does not throw, returns the result. If it does throw, adds the exception to the given {@link ExceptionStore} and returns false. This method can help with implementing the exception-handling policy described above, but note that assertions using it <i>...
safeCompare
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
public @Nullable String formatDiff(A actual, E expected) { return null; }
Returns a {@link String} describing the difference between the {@code actual} and {@code expected} values, if possible, or {@code null} if not. <p>The implementation on the {@link Correspondence} base class always returns {@code null}. To enable diffing, use {@link #formattingDiffsUsing} (or override this method in a ...
formatDiff
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
final @Nullable String safeFormatDiff(A actual, E expected, ExceptionStore exceptions) { try { return formatDiff(actual, expected); } catch (RuntimeException e) { exceptions.addFormatDiffException(Correspondence.class, e, actual, expected); return null; } }
Invokes {@link #formatDiff}, catching any exceptions. If the comparison does not throw, returns the result. If it does throw, adds the exception to the given {@link ExceptionStore} and returns null.
safeFormatDiff
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
boolean isEquality() { return false; }
Returns whether this is an equality correspondence, i.e. one returned by {@link #equality} or one whose {@link #compare} delegates to one returned by {@link #equality}.
isEquality
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
final ImmutableList<Fact> describeForIterable() { if (!isEquality()) { return ImmutableList.of( fact("testing whether", "actual element " + this + " expected element")); } else { return ImmutableList.of(); } }
Returns a list of {@link Fact} instance describing how this correspondence compares elements of an iterable. There will be one "testing whether" fact, unless this {@link #isEquality is an equality correspondence}, in which case the list will be empty.
describeForIterable
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
final ImmutableList<Fact> describeForMapValues() { if (!isEquality()) { return ImmutableList.of(fact("testing whether", "actual value " + this + " expected value")); } else { return ImmutableList.of(); } }
Returns a list of {@link Fact} instance describing how this correspondence compares values in a map (or multimap). There will be one "testing whether" fact, unless this {@link #isEquality is an equality correspondence}, in which case the list will be empty.
describeForMapValues
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
@Deprecated @Override public final boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "Correspondence.equals(object) is not supported. If you meant to compare objects, use" + " .compare(actual, expected) instead."); }
@throws UnsupportedOperationException always @deprecated {@link Object#equals(Object)} is not supported. If you meant to compare objects using this {@link Correspondence}, use {@link #compare}.
equals
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
@Deprecated @Override public final int hashCode() { throw new UnsupportedOperationException("Correspondence.hashCode() is not supported."); }
@throws UnsupportedOperationException always @deprecated {@link Object#hashCode()} is not supported.
hashCode
java
google/truth
core/src/main/java/com/google/common/truth/Correspondence.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Correspondence.java
Apache-2.0
protected final FailureMetadata metadata() { return metadata; }
Returns the {@link FailureMetadata} instance that {@code that} methods should pass to {@link Subject} constructors.
metadata
java
google/truth
core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java
Apache-2.0
private List<String> diff( List<String> originalLines, List<String> revisedLines, int contextSize) { reduceEqualLinesFromHeadAndTail(originalLines, revisedLines, contextSize); originalLines = originalLines.subList(offsetHead, originalLines.size() - offsetTail); revisedLines = revisedLines.subList(offs...
A custom implementation of the diff algorithm based on the solution described at https://en.wikipedia.org/wiki/Longest_common_subsequence_problem @author Yun Peng (pcloudy@google.com)
diff
java
google/truth
core/src/main/java/com/google/common/truth/DiffUtils.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DiffUtils.java
Apache-2.0
private Integer getIdByLine(String line) { int newId = stringList.size(); Integer existingId = stringToId.put(line, newId); if (existingId == null) { stringList.add(line); return newId; } else { stringToId.put(line, existingId); return existingId; } }
Calculate an incremental Id for a given string.
getIdByLine
java
google/truth
core/src/main/java/com/google/common/truth/DiffUtils.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DiffUtils.java
Apache-2.0
@Deprecated @Override public boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to compare doubles, use .of(double) instead."); }
@throws UnsupportedOperationException always @deprecated {@link Object#equals(Object)} is not supported on TolerantDoubleComparison. If you meant to compare doubles, use {@link #of(double)} instead.
equals
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public TolerantDoubleComparison isWithin(double tolerance) { return TolerantDoubleComparison.comparing( other -> { if (!Double.isFinite(tolerance)) { failWithoutActual( simpleFact( "could not perform approximate-equality check because tolerance is no...
Prepares for a check that the actual value is a finite number within the given tolerance of an expected value that will be provided in the next call in the fluent chain. <p>The check will fail if either the actual value or the expected value is {@link Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, or {@l...
isWithin
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public TolerantDoubleComparison isNotWithin(double tolerance) { return TolerantDoubleComparison.comparing( other -> { if (!Double.isFinite(tolerance)) { failWithoutActual( simpleFact( "could not perform approximate-equality check because tolerance is...
Prepares for a check that the actual value is a finite number not within the given tolerance of an expected value that will be provided in the next call in the fluent chain. <p>The check will fail if either the actual value or the expected value is {@link Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, or...
isNotWithin
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
@Override public void isEqualTo(@Nullable Object other) { super.isEqualTo(other); }
Asserts that the actual value is exactly equal to the given value, with equality defined as by {@code Double#equals}. This method is <i>not</i> recommended when the code under test is doing any kind of arithmetic: use {@link #isWithin} with a suitable tolerance in that case. (Remember that the exact result of floating ...
isEqualTo
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
@Override public void isNotEqualTo(@Nullable Object other) { super.isNotEqualTo(other); }
Asserts that the actual value is not exactly equal to the given value, with equality defined as by {@code Double#equals}. See {@link #isEqualTo} for advice on when exact equality is recommended. Use {@link #isNotWithin} for an assertion with a tolerance. <p><b>Note:</b> The assertion {@code isNotEqualTo(0.0)} passes f...
isNotEqualTo
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public void isZero() { if (actual == null || actual != 0.0) { failWithActual(simpleFact("expected zero")); } }
Asserts that the actual value is zero (i.e. it is either {@code 0.0} or {@code -0.0}).
isZero
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public void isNonZero() { if (actual == null) { failWithActual(simpleFact("expected a double other than zero")); } else if (actual == 0.0) { failWithActual(simpleFact("expected not to be zero")); } }
Asserts that the actual value is a non-null value other than zero (i.e. it is not {@code 0.0}, {@code -0.0} or {@code null}).
isNonZero
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public void isFinite() { if (actual == null || actual.isNaN() || actual.isInfinite()) { failWithActual(simpleFact("expected to be finite")); } }
Asserts that the actual value is finite, i.e. not {@link Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, or {@link Double#NaN}.
isFinite
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
public void isNotNaN() { if (actual == null) { failWithActual(simpleFact("expected a double other than NaN")); } else { isNotEqualTo(NaN); } }
Asserts that the actual value is a non-null value other than {@link Double#NaN} (but it may be {@link Double#POSITIVE_INFINITY} or {@link Double#NEGATIVE_INFINITY}).
isNotNaN
java
google/truth
core/src/main/java/com/google/common/truth/DoubleSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/DoubleSubject.java
Apache-2.0
void enterRuleContext() { this.inRuleContext = true; }
Enters rule context to be ready to capture failures. <p>This should be used only from framework code. This normally means from the {@link #apply} method below, but our tests call it directly under J2CL.
enterRuleContext
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
void leaveRuleContext() { this.inRuleContext = false; }
Leaves rule context and verify if a failure has been caught if it's expected.
leaveRuleContext
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
void ensureFailureCaught() { if (failureExpected && failure == null) { throw new AssertionError( "ExpectFailure.whenTesting() invoked, but no failure was caught." + Platform.EXPECT_FAILURE_WARNING_IF_GWT); } }
Ensures a failure is caught if it's expected (i.e., {@link #whenTesting} is called) and throws error if not.
ensureFailureCaught
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
public AssertionError getFailure() { if (failure == null) { throw new AssertionError("ExpectFailure did not capture a failure."); } return failure; }
Legacy method that returns the failure captured by {@link #whenTesting}, if one occurred.
getFailure
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
private void captureFailure(AssertionError captured) { if (failure != null) { // TODO(diamondm) is it worthwhile to add the failures as suppressed exceptions? throw new AssertionError( lenientFormat( "ExpectFailure.whenTesting() caught multiple failures:\n\n%s\n\n%s\n", ...
Captures the provided failure, or throws an {@link AssertionError} if a failure had previously been captured.
captureFailure
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
@CanIgnoreReturnValue public static AssertionError expectFailure(StandardSubjectBuilderCallback assertionCallback) { ExpectFailure expectFailure = new ExpectFailure(); expectFailure.enterRuleContext(); // safe since this instance doesn't leave this method assertionCallback.invokeAssertion(expectFailure.wh...
Captures and returns the failure produced by the assertion in the provided callback, similar to {@code assertThrows()}: <p>{@code AssertionError failure = expectFailure(whenTesting -> whenTesting.that(4).isNotEqualTo(4));}
expectFailure
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
@CanIgnoreReturnValue public static <S extends Subject, A> AssertionError expectFailureAbout( Subject.Factory<S, A> factory, SimpleSubjectBuilderCallback<S, A> assertionCallback) { return expectFailure( whenTesting -> assertionCallback.invokeAssertion(whenTesting.about(factory))); }
Captures and returns the failure produced by the assertion in the provided callback, similar to {@code assertThrows()}: <p>{@code AssertionError failure = expectFailureAbout(myTypes(), whenTesting -> whenTesting.that(myType).hasProperty());}
expectFailureAbout
java
google/truth
core/src/main/java/com/google/common/truth/ExpectFailure.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ExpectFailure.java
Apache-2.0
public static Fact fact(String key, @Nullable Object value) { return new Fact(key, String.valueOf(value), /* padStart= */ false); }
Creates a fact with the given key and value, which will be printed in a format like "key: value." The value is converted to a string by calling {@code String.valueOf} on it.
fact
java
google/truth
core/src/main/java/com/google/common/truth/Fact.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Fact.java
Apache-2.0
public static Fact simpleFact(String key) { return new Fact(key, null, /* padStart= */ false); }
Creates a fact with no value, which will be printed in the format "key" (with no colon or value). <p>In most cases, prefer {@linkplain #fact key-value facts}, which give Truth more flexibility in how to format the fact for display. {@code simpleFact} is useful primarily for: <ul> <li>messages from no-arg assertions...
simpleFact
java
google/truth
core/src/main/java/com/google/common/truth/Fact.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Fact.java
Apache-2.0
@Override public String toString() { return value == null ? key : key + ": " + value; }
Returns a simple string representation for the fact. While this is used in the output of {@code TruthFailureSubject}, it's not used in normal failure messages, which automatically align facts horizontally and indent multiline values.
toString
java
google/truth
core/src/main/java/com/google/common/truth/Fact.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Fact.java
Apache-2.0
static FailureMetadata forFailureStrategy(FailureStrategy failureStrategy) { return new FailureMetadata( failureStrategy, /* messages= */ ImmutableList.of(), /* steps= */ ImmutableList.of()); }
An opaque, immutable object containing state from the previous calls in the fluent assertion chain. It appears primarily as a parameter to {@link Subject} constructors (and {@link Subject.Factory} methods), which should pass it to the superclass constructor and not otherwise use or store it. In particular, users should...
forFailureStrategy
java
google/truth
core/src/main/java/com/google/common/truth/FailureMetadata.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FailureMetadata.java
Apache-2.0
private ImmutableList<Fact> description() { return description(/* factKey= */ "value of"); }
Returns a description of the final actual value, if it appears "interesting" enough to show. The description is considered interesting if the chain of derived subjects ends with at least one derivation that we have a name for. It's also considered interesting in the absence of derived subjects if we inferred a name for...
description
java
google/truth
core/src/main/java/com/google/common/truth/FailureMetadata.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FailureMetadata.java
Apache-2.0
private ImmutableList<Fact> description(String factKey) { String description = inferDescription(); boolean descriptionIsInteresting = description != null; for (Step step : steps) { if (step.isCheckCall()) { checkState(description != null); if (step.descriptionUpdate == null) { ...
Overload of {@link #description()} that allows passing a custom key for the fact.
description
java
google/truth
core/src/main/java/com/google/common/truth/FailureMetadata.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FailureMetadata.java
Apache-2.0
private ImmutableList<Fact> rootUnlessThrowable() { Step rootSubject = null; boolean seenDerivation = false; for (Step step : steps) { if (step.isCheckCall()) { /* * If we don't have a description update, don't trigger display of a root object. (If we * did, we'd change the m...
Returns the root actual value, if we know it's "different enough" from the final actual value. <p>We don't want to say: "expected [foo] but was [bar]. string: [bar]" <p>We do want to say: "expected [foo] but was [bar]. myObject: MyObject[string=bar, i=0]" <p>To support that, {@code seenDerivation} tracks whether we'...
rootUnlessThrowable
java
google/truth
core/src/main/java/com/google/common/truth/FailureMetadata.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FailureMetadata.java
Apache-2.0
private @Nullable Throwable rootCause() { for (Step step : steps) { if (!step.isCheckCall() && checkNotNull(step.subject).actual() instanceof Throwable) { return (Throwable) step.subject.actual(); } } return null; }
Returns the first {@link Throwable} in the chain of actual values. Typically, we'll have a root cause only if the assertion chain contains a {@link ThrowableSubject}.
rootCause
java
google/truth
core/src/main/java/com/google/common/truth/FailureMetadata.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FailureMetadata.java
Apache-2.0
@Deprecated @Override public boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to compare floats, use .of(float) instead."); }
@throws UnsupportedOperationException always @deprecated {@link Object#equals(Object)} is not supported on TolerantFloatComparison. If you meant to compare floats, use {@link #of(float)} instead.
equals
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public TolerantFloatComparison isWithin(float tolerance) { return TolerantFloatComparison.create( other -> { if (!Float.isFinite(tolerance)) { failWithoutActual( simpleFact( "could not perform approximate-equality check because tolerance is not finit...
Prepares for a check that the actual value is a finite number within the given tolerance of an expected value that will be provided in the next call in the fluent chain. <p>The check will fail if either the actual value or the expected value is {@link Float#POSITIVE_INFINITY}, {@link Float#NEGATIVE_INFINITY}, or {@lin...
isWithin
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public TolerantFloatComparison isNotWithin(float tolerance) { return TolerantFloatComparison.create( other -> { if (!Float.isFinite(tolerance)) { failWithoutActual( simpleFact( "could not perform approximate-equality check because tolerance is not fi...
Prepares for a check that the actual value is a finite number not within the given tolerance of an expected value that will be provided in the next call in the fluent chain. <p>The check will fail if either the actual value or the expected value is {@link Float#POSITIVE_INFINITY}, {@link Float#NEGATIVE_INFINITY}, or {...
isNotWithin
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
@Override public void isEqualTo(@Nullable Object other) { super.isEqualTo(other); }
Asserts that the actual value is exactly equal to the given value, with equality defined as by {@code Float#equals}. This method is <i>not</i> recommended when the code under test is doing any kind of arithmetic: use {@link #isWithin} with a suitable tolerance in that case. (Remember that the exact result of floating p...
isEqualTo
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
@Override public void isNotEqualTo(@Nullable Object other) { super.isNotEqualTo(other); }
Asserts that the actual value is not exactly equal to the given value, with equality defined as by {@code Float#equals}. See {@link #isEqualTo} for advice on when exact equality is recommended. Use {@link #isNotWithin} for an assertion with a tolerance. <p><b>Note:</b> The assertion {@code isNotEqualTo(0.0f)} passes f...
isNotEqualTo
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public void isZero() { if (actual == null || actual != 0.0f) { failWithActual(simpleFact("expected zero")); } }
Asserts that the actual value is zero (i.e. it is either {@code 0.0f} or {@code -0.0f}).
isZero
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public void isNonZero() { if (actual == null) { failWithActual(simpleFact("expected a float other than zero")); } else if (actual == 0.0f) { failWithActual(simpleFact("expected not to be zero")); } }
Asserts that the actual value is a non-null value other than zero (i.e. it is not {@code 0.0f}, {@code -0.0f} or {@code null}).
isNonZero
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public void isFinite() { if (actual == null || actual.isNaN() || actual.isInfinite()) { failWithActual(simpleFact("expected to be finite")); } }
Asserts that the actual value is finite, i.e. not {@link Float#POSITIVE_INFINITY}, {@link Float#NEGATIVE_INFINITY}, or {@link Float#NaN}.
isFinite
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
public void isNotNaN() { if (actual == null) { failWithActual(simpleFact("expected a float other than NaN")); } else { isNotEqualTo(NaN); } }
Asserts that the actual value is a non-null value other than {@link Float#NaN} (but it may be {@link Float#POSITIVE_INFINITY} or {@link Float#NEGATIVE_INFINITY}).
isNotNaN
java
google/truth
core/src/main/java/com/google/common/truth/FloatSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java
Apache-2.0
static <U, V> ImmutableBiMap<U, V> maximumCardinalityBipartiteMatching(Multimap<U, V> graph) { return HopcroftKarp.overBipartiteGraph(graph).perform(); }
Finds a <a href="https://en.wikipedia.org/wiki/Matching_(graph_theory)#In_unweighted_bipartite_graphs"> maximum cardinality matching of a bipartite graph</a>. The vertices of one part of the bipartite graph are identified by objects of type {@code U} using object equality. The vertices of the other part are similarly i...
maximumCardinalityBipartiteMatching
java
google/truth
core/src/main/java/com/google/common/truth/GraphMatching.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java
Apache-2.0
static <U, V> HopcroftKarp<U, V> overBipartiteGraph(Multimap<U, V> graph) { return new HopcroftKarp<>(graph); }
Factory method which returns an instance ready to perform the algorithm over the bipartite graph described by the given multimap.
overBipartiteGraph
java
google/truth
core/src/main/java/com/google/common/truth/GraphMatching.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java
Apache-2.0
ImmutableBiMap<U, V> perform() { BiMap<U, V> matching = HashBiMap.create(); while (true) { // Perform the BFS as described below. This finds the length of the shortest augmenting path // and a guide which locates all the augmenting paths of that length. Map<U, Integer> layers = new H...
Performs the algorithm, and returns a bimap describing the matching found.
perform
java
google/truth
core/src/main/java/com/google/common/truth/GraphMatching.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java
Apache-2.0
private @Nullable Integer breadthFirstSearch(BiMap<U, V> matching, Map<U, Integer> layers) { Queue<U> queue = new ArrayDeque<>(); Integer freeRhsVertexLayer = null; // Enqueue all free LHS vertices and assign them to layer 1. for (U lhs : graph.keySet()) { if (!matching.containsKey(lhs)...
Performs the Breadth-First Search phase of the algorithm. Specifically, treats the bipartite graph as a directed graph where every unmatched edge (i.e. every edge not in the current matching) is directed from the LHS vertex to the RHS vertex and every matched edge is directed from the RHS vertex to the LHS vertex, and ...
breadthFirstSearch
java
google/truth
core/src/main/java/com/google/common/truth/GraphMatching.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java
Apache-2.0
@CanIgnoreReturnValue private boolean depthFirstSearch( BiMap<U, V> matching, Map<U, Integer> layers, int freeRhsVertexLayer, U lhs) { // Note that this differs from the method described in the text of the wikipedia article (at // time of writing) in two ways. Firstly, we proceed from a free LHS...
Performs the Depth-First Search phase of the algorithm. The DFS is guided by the BFS phase, i.e. it only uses paths which were used in the BFS. That means the steps in the DFS proceed from an LHS vertex via an unmatched edge to an RHS vertex and from an RHS vertex via a matched edge to an LHS vertex only if that LHS ve...
depthFirstSearch
java
google/truth
core/src/main/java/com/google/common/truth/GraphMatching.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java
Apache-2.0
@Deprecated @Override public boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to compare ints, use .of(int) instead."); }
@throws UnsupportedOperationException always @deprecated {@link Object#equals(Object)} is not supported on TolerantIntegerComparison. If you meant to compare ints, use {@link #of(int)} instead.
equals
java
google/truth
core/src/main/java/com/google/common/truth/IntegerSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java
Apache-2.0
@Deprecated @SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely. public static Factory<IntStreamSubject, IntStream> intStreams() { return IntStreamSubject::new; }
Obsolete factory instance. This factory was previously necessary for assertions like {@code assertWithMessage(...).about(intStreams()).that(stream)....}. Now, you can perform assertions like that without the {@code about(...)} call. @deprecated Instead of {@code about(intStreams()).that(...)}, use just {@code that(......
intStreams
java
google/truth
core/src/main/java/com/google/common/truth/IntStreamSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java
Apache-2.0
public final void isEmpty() { if (!Iterables.isEmpty(checkNotNull(actual))) { failWithActual(simpleFact("expected to be empty")); } }
Checks that the actual iterable is empty.
isEmpty
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void isNotEmpty() { if (Iterables.isEmpty(checkNotNull(actual))) { failWithoutActual(simpleFact("expected not to be empty")); } }
Checks that the actual iterable is not empty.
isNotEmpty
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void hasSize(int expectedSize) { checkArgument(expectedSize >= 0, "expectedSize(%s) must be >= 0", expectedSize); int actualSize = size(checkNotNull(actual)); check("size()").that(actualSize).isEqualTo(expectedSize); }
Checks that the actual iterable has the given size.
hasSize
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void contains(@Nullable Object element) { if (!Iterables.contains(checkNotNull(actual), element)) { List<@Nullable Object> elementList = asList(element); if (hasMatchingToStringPair(actual, elementList)) { failWithoutActual( fact("expected to contain", element), ...
Checks that the actual iterable contains the supplied item.
contains
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void doesNotContain(@Nullable Object element) { if (Iterables.contains(checkNotNull(actual), element)) { failWithActual("expected not to contain", element); } }
Checks that the actual iterable does not contain the supplied item.
doesNotContain
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void containsNoDuplicates() { List<Multiset.Entry<?>> duplicates = new ArrayList<>(); for (Multiset.Entry<?> entry : LinkedHashMultiset.create(checkNotNull(actual)).entrySet()) { if (entry.getCount() > 1) { duplicates.add(entry); } } if (!duplicates.isEmpty()) { fa...
Checks that the actual iterable does not contain duplicate elements.
containsNoDuplicates
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void containsAnyOf( @Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) { containsAnyIn(accumulate(first, second, rest)); }
Checks that the actual iterable contains at least one of the provided objects.
containsAnyOf
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void containsAnyIn(@Nullable Iterable<?> expected) { checkNotNull(expected); Collection<?> actual = iterableToCollection(checkNotNull(this.actual)); for (Object item : expected) { if (actual.contains(item)) { return; } } if (hasMatchingToStringPair(actual, expected))...
Checks that the actual iterable contains at least one of the objects contained in the provided collection.
containsAnyIn
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@SuppressWarnings("AvoidObjectArrays") public final void containsAnyIn(@Nullable Object[] expected) { containsAnyIn(asList(expected)); }
Checks that the actual iterable contains at least one of the objects contained in the provided array.
containsAnyIn
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@CanIgnoreReturnValue public final Ordered containsAtLeast( @Nullable Object firstExpected, @Nullable Object secondExpected, @Nullable Object @Nullable ... restOfExpected) { return containsAtLeastElementsIn(accumulate(firstExpected, secondExpected, restOfExpected)); }
Checks that the actual iterable contains at least all the expected elements. If an element appears more than once in the expected elements to this call then it must appear at least that number of times in the actual elements. <p>To also test that the contents appear in the given order, make a call to {@code inOrder()}...
containsAtLeast
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
private static void moveElements( List<?> input, Collection<@Nullable Object> output, int maxElements) { for (int i = 0; i < maxElements; i++) { output.add(input.remove(0)); } }
Removes at most the given number of available elements from the input list and adds them to the given output collection.
moveElements
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@CanIgnoreReturnValue public final Ordered containsExactly(@Nullable Object @Nullable ... expected) { List<@Nullable Object> expectedAsList = expected == null ? asList((@Nullable Object) null) : asList(expected); return containsExactlyElementsIn( expectedAsList, expected != null && exp...
Checks that the actual iterable contains exactly the provided objects. <p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the parameters asserts that the object must likewise be duplicated exactly 3 times in the actual iterable. <p>To also test that the contents appear in the given ord...
containsExactly
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@CanIgnoreReturnValue public final Ordered containsExactlyElementsIn(@Nullable Iterable<?> expected) { return containsExactlyElementsIn(expected, /* addElementsInWarning= */ false); }
Checks that the actual iterable contains exactly the provided objects. <p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the {@code Iterable} parameter asserts that the object must likewise be duplicated exactly 3 times in the actual iterable. <p>To also test that the contents appear ...
containsExactlyElementsIn
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public final void containsNoneOf( @Nullable Object firstExcluded, @Nullable Object secondExcluded, @Nullable Object @Nullable ... restOfExcluded) { containsNoneIn(accumulate(firstExcluded, secondExcluded, restOfExcluded)); } /** * Checks that the actual iterable contains none of the elemen...
Checks that the actual iterable contains none of the excluded objects.
containsNoneOf
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@SuppressWarnings("AvoidObjectArrays") public final void containsNoneIn(@Nullable Object[] excluded) { containsNoneIn(asList(excluded)); }
Checks that the actual iterable contains none of the elements contained in the excluded array.
containsNoneIn
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@SuppressWarnings({"unchecked"}) public final void isInStrictOrder(Comparator<?> comparator) { checkNotNull(comparator); pairwiseCheck( "expected to be in strict order", (prev, next) -> ((Comparator<@Nullable Object>) comparator).compare(prev, next) < 0); }
Checks that the actual iterable is strictly ordered, according to the given comparator. Strictly ordered means that each element in the iterable is <i>strictly</i> greater than the element that preceded it. @throws ClassCastException if any pair of elements is not mutually Comparable
isInStrictOrder
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@Override @Deprecated public void isNoneOf( @Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) { super.isNoneOf(first, second, rest); }
@deprecated You probably meant to call {@link #containsNoneOf} instead.
isNoneOf
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public <A extends @Nullable Object, E extends @Nullable Object> UsingCorrespondence<A, E> comparingElementsUsing( Correspondence<? super A, ? super E> correspondence) { return new UsingCorrespondence<>(this, correspondence); }
Starts a method chain for a check in which the actual elements (i.e. the elements of the {@link Iterable} under test) are compared to expected elements using the given {@link Correspondence}. The actual elements must be of type {@code A}, the expected elements must be of type {@code E}. The check is actually executed b...
comparingElementsUsing
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public <T extends @Nullable Object> UsingCorrespondence<T, T> formattingDiffsUsing( DiffFormatter<? super T, ? super T> formatter) { return comparingElementsUsing(Correspondence.<T>equality().formattingDiffsUsing(formatter)); }
Starts a method chain for a check in which failure messages may use the given {@link DiffFormatter} to describe the difference between an actual element (i.e. an element of the {@link Iterable} under test) and the element it is expected to be equal to, but isn't. The actual and expected elements must be of type {@code ...
formattingDiffsUsing
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@DoNotCall( "UsingCorrespondence.equals() is not supported. Did you mean to call" + " containsExactlyElementsIn(expected) instead of equals(expected)?") @Deprecated @Override public final boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "Using...
@throws UnsupportedOperationException always @deprecated {@link Object#equals(Object)} is not supported on Truth subjects or intermediate classes. If you are writing a test assertion (actual vs. expected), use methods liks {@link #containsExactlyElementsIn(Iterable)} instead.
equals
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@DoNotCall("UsingCorrespondence.hashCode() is not supported.") @Deprecated @Override public final int hashCode() { throw new UnsupportedOperationException("UsingCorrespondence.hashCode() is not supported."); }
@throws UnsupportedOperationException always @deprecated {@link Object#hashCode()} is not supported on Truth types.
hashCode
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public UsingCorrespondence<A, E> displayingDiffsPairedBy(Function<? super E, ?> keyFunction) { @SuppressWarnings("unchecked") // throwing ClassCastException is the correct behaviour Function<? super A, ?> actualKeyFunction = (Function<? super A, ?>) keyFunction; return displayingDiffsPairedBy(actualKe...
Specifies a way to pair up unexpected and missing elements in the message when an assertion fails. For example: <pre>{@code assertThat(actualRecords) .comparingElementsUsing(RECORD_CORRESPONDENCE) .displayingDiffsPairedBy(MyRecord::getId) .containsExactlyElementsIn(expectedRecords); }</pre> <p><b>Importan...
displayingDiffsPairedBy
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public UsingCorrespondence<A, E> displayingDiffsPairedBy( Function<? super A, ?> actualKeyFunction, Function<? super E, ?> expectedKeyFunction) { return new UsingCorrespondence<>( subject, correspondence, Pairer.create(actualKeyFunction, expectedKeyFunction)); }
Specifies a way to pair up unexpected and missing elements in the message when an assertion fails. For example: <pre>{@code assertThat(actualFoos) .comparingElementsUsing(FOO_BAR_CORRESPONDENCE) .displayingDiffsPairedBy(Foo::getId, Bar::getFooId) .containsExactlyElementsIn(expectedBar); }</pre> <p>On asse...
displayingDiffsPairedBy
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public void contains(E expected) { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); for (A actual : getCastActual()) { if (correspondence.safeCompare(actual, expected, exceptions)) { // Found a match, but we still need to fail if we hit an exception a...
Checks that the actual iterable contains at least one element that corresponds to the given expected element.
contains
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
public void doesNotContain(E excluded) { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); List<A> matchingElements = new ArrayList<>(); for (A actual : getCastActual()) { if (correspondence.safeCompare(actual, excluded, exceptions)) { matchingEl...
Checks that none of the actual elements correspond to the given element.
doesNotContain
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
@SafeVarargs @CanIgnoreReturnValue public final Ordered containsExactly(@Nullable E @Nullable ... expected) { return containsExactlyElementsIn(expected == null ? asList((E) null) : asList(expected)); }
Checks that actual iterable contains exactly elements that correspond to the expected elements, i.e. that there is a 1:1 mapping between the actual elements and the expected elements where each pair of elements correspond. <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} on...
containsExactly
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
private boolean correspondInOrderExactly( Iterator<? extends A> actual, Iterator<? extends E> expected) { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); while (actual.hasNext() && expected.hasNext()) { A actualElement = actual.next(); E expect...
Returns whether the actual and expected iterators have the same number of elements and, when iterated pairwise, every pair of actual and expected values satisfies the correspondence. Returns false if any comparison threw an exception.
correspondInOrderExactly
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
private ImmutableSetMultimap<Integer, Integer> findCandidateMapping( List<? extends A> actual, List<? extends E> expected, Correspondence.ExceptionStore exceptions) { ImmutableSetMultimap.Builder<Integer, Integer> mapping = ImmutableSetMultimap.builder(); for (int actualIndex = 0; ac...
Given a list of actual elements and a list of expected elements, finds a many:many mapping between actual and expected elements where a pair of elements maps if it satisfies the correspondence. Returns this mapping as a multimap where the keys are indexes into the actual list and the values are indexes into the expecte...
findCandidateMapping
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
private boolean failIfCandidateMappingHasMissingOrExtra( List<? extends A> actual, List<? extends E> expected, ImmutableSetMultimap<Integer, Integer> mapping, Correspondence.ExceptionStore exceptions) { List<? extends A> extra = findNotIndexed(actual, mapping.keySet()); List<...
Given a list of actual elements, a list of expected elements, and a many:many mapping between actual and expected elements specified as a multimap of indexes into the actual list to indexes into the expected list, checks that every actual element maps to at least one expected element and vice versa, and fails if this i...
failIfCandidateMappingHasMissingOrExtra
java
google/truth
core/src/main/java/com/google/common/truth/IterableSubject.java
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java
Apache-2.0
End of preview. Expand in Data Studio

Java CodeSearch Dataset (Shuu12121/java-treesitter-dedupe_doc-filtered-dataset)

Dataset Description

This dataset contains Java methods paired with their Javadoc comments, extracted from open-source Java repositories on GitHub. It is formatted similarly to the CodeSearchNet challenge dataset.

Each entry includes:

  • code: The source code of a java function or method.
  • docstring: The docstring or Javadoc associated with the function/method.
  • func_name: The name of the function/method.
  • language: The programming language (always "java").
  • repo: The GitHub repository from which the code was sourced (e.g., "owner/repo").
  • path: The file path within the repository where the function/method is located.
  • url: A direct URL to the function/method's source file on GitHub (approximated to master/main branch).
  • license: The SPDX identifier of the license governing the source repository (e.g., "MIT", "Apache-2.0"). Additional metrics if available (from Lizard tool):
  • ccn: Cyclomatic Complexity Number.
  • params: Number of parameters of the function/method.
  • nloc: Non-commenting lines of code.
  • token_count: Number of tokens in the function/method.

Dataset Structure

The dataset is divided into the following splits:

  • train: 1,553,016 examples
  • validation: 15,165 examples
  • test: 17,927 examples

Data Collection

The data was collected by:

  1. Identifying popular and relevant Java repositories on GitHub.
  2. Cloning these repositories.
  3. Parsing Java files (.java) using tree-sitter to extract functions/methods and their docstrings/Javadoc.
  4. Filtering functions/methods based on code length and presence of a non-empty docstring/Javadoc.
  5. Using the lizard tool to calculate code metrics (CCN, NLOC, params).
  6. Storing the extracted data in JSONL format, including repository and license information.
  7. Splitting the data by repository to ensure no data leakage between train, validation, and test sets.

Intended Use

This dataset can be used for tasks such as:

  • Training and evaluating models for code search (natural language to code).
  • Code summarization / docstring generation (code to natural language).
  • Studies on Java code practices and documentation habits.

Licensing

The code examples within this dataset are sourced from repositories with permissive licenses (typically MIT, Apache-2.0, BSD). Each sample includes its original license information in the license field. The dataset compilation itself is provided under a permissive license (e.g., MIT or CC-BY-SA-4.0), but users should respect the original licenses of the underlying code.

Example Usage

from datasets import load_dataset

# Load the dataset
dataset = load_dataset("Shuu12121/java-treesitter-dedupe_doc-filtered-dataset")

# Access a split (e.g., train)
train_data = dataset["train"]

# Print the first example
print(train_data[0])
Downloads last month
41

Models trained or fine-tuned on Shuu12121/java-treesitter-dedupe_doc-filtered-dataset

Collection including Shuu12121/java-treesitter-dedupe_doc-filtered-dataset