Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: google/truth
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.5
Choose a base ref
...
head repository: google/truth
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.0
Choose a head ref
Loading
Showing with 1,022 additions and 235 deletions.
  1. +10 −10 .github/workflows/ci.yml
  2. +4 −4 core/pom.xml
  3. +1 −1 core/src/main/java/com/google/common/truth/Correspondence.java
  4. +110 −2 core/src/main/java/com/google/common/truth/IntegerSubject.java
  5. +3 −3 core/src/main/java/com/google/common/truth/IterableSubject.java
  6. +109 −0 core/src/main/java/com/google/common/truth/LongSubject.java
  7. +34 −0 core/src/main/java/com/google/common/truth/MathUtil.java
  8. +7 −2 core/src/main/java/com/google/common/truth/Platform.java
  9. +2 −9 core/src/main/java/com/google/common/truth/Subject.java
  10. +6 −1 core/src/main/java/com/google/common/truth/SubjectUtils.java
  11. +4 −0 core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java
  12. +113 −146 core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
  13. +138 −0 core/src/test/java/com/google/common/truth/LongSubjectTest.java
  14. +194 −0 core/src/test/java/com/google/common/truth/NumericComparisonTest.java
  15. +1 −1 extensions/java8/pom.xml
  16. +1 −1 extensions/liteproto/pom.xml
  17. +1 −1 extensions/pom.xml
  18. +1 −1 extensions/proto/pom.xml
  19. +5 −5 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
  20. +3 −0 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
  21. +28 −11 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldNumberTree.java
  22. +11 −4 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeImpl.java
  23. +23 −7 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopeLogic.java
  24. +77 −2 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FieldScopes.java
  25. +5 −1 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FluentEqualityConfig.java
  26. +8 −3 ...ns/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java
  27. +11 −1 extensions/proto/src/main/java/com/google/common/truth/extensions/proto/SubScopeId.java
  28. +90 −0 extensions/proto/src/test/java/com/google/common/truth/extensions/proto/FieldScopesTest.java
  29. +1 −1 extensions/re2j/pom.xml
  30. +19 −17 pom.xml
  31. +2 −1 ...rings/src/main/java/com/google/common/truth/refactorings/CorrespondenceSubclassToFactoryCall.java
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -18,20 +18,20 @@ jobs:
steps:
# Cancel any previous runs for the same branch that are still running.
- name: 'Cancel previous runs'
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432
with:
access_token: ${{ github.token }}
- name: 'Check out repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: 'Cache local Maven repository'
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
@@ -52,16 +52,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: 'Cache local Maven repository'
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
- name: 'Set up JDK 11'
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
with:
java-version: 11
distribution: 'zulu'
@@ -81,16 +81,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: 'Cache local Maven repository'
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
- name: 'Set up JDK 11'
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
with:
java-version: 11
distribution: 'zulu'
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<parent>
<groupId>com.google.truth</groupId>
<artifactId>truth-parent</artifactId>
<version>HEAD-SNAPSHOT</version>
<version>1.2.0</version>
</parent>
<artifactId>truth</artifactId>
<name>Truth Core</name>
@@ -138,7 +138,7 @@
<goals><goal>test</goal></goals>
<configuration>
<mode>htmlunit</mode>
<htmlunit>FF38</htmlunit>
<htmlunit>FF</htmlunit>
<productionMode>true</productionMode>
<!-- Fix OutOfMemoryError in Travis. -->
<extraJvmArgs>-Xms3500m -Xmx3500m -Xss1024k</extraJvmArgs>
@@ -165,7 +165,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<executions>
<execution>
<id>add-source</id>
@@ -227,7 +227,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version>
<version>3.5.0</version>
</plugin>
</plugins>
</reporting>
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Platform.getStackTraceAsString;
import static java.util.Arrays.asList;
import static com.google.common.truth.SubjectUtils.asList;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
112 changes: 110 additions & 2 deletions core/src/main/java/com/google/common/truth/IntegerSubject.java
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@
*/
package com.google.common.truth;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.MathUtil.equalWithinTolerance;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
@@ -25,12 +30,110 @@
* @author Kurt Alfred Kluever
*/
public class IntegerSubject extends ComparableSubject<Integer> {
private final @Nullable Integer actual;

/**
* Constructor for use by subclasses. If you want to create an instance of this class itself, call
* {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}.
*/
protected IntegerSubject(FailureMetadata metadata, @Nullable Integer integer) {
super(metadata, integer);
protected IntegerSubject(FailureMetadata metadata, @Nullable Integer actual) {
super(metadata, actual);
this.actual = actual;
}

/**
* A partially specified check about an approximate relationship to a {@code int} subject using a
* tolerance.
*
* @since 1.2
*/
public abstract static class TolerantIntegerComparison {

// Prevent subclassing outside of this class
private TolerantIntegerComparison() {}

/**
* Fails if the subject was expected to be within the tolerance of the given value but was not
* <i>or</i> if it was expected <i>not</i> to be within the tolerance but was. The subject and
* tolerance are specified earlier in the fluent call chain.
*/
public abstract void of(int expectedInteger);

/**
* @throws UnsupportedOperationException always
* @deprecated {@link Object#equals(Object)} is not supported on TolerantIntegerComparison. If
* you meant to compare ints, use {@link #of(int)} instead.
*/
@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#hashCode()} is not supported on TolerantIntegerComparison
*/
@Deprecated
@Override
public int hashCode() {
throw new UnsupportedOperationException("Subject.hashCode() is not supported.");
}
}

/**
* Prepares for a check that the subject is a number within the given tolerance of an expected
* value that will be provided in the next call in the fluent chain.
*
* @param tolerance an inclusive upper bound on the difference between the subject and object
* allowed by the check, which must be a non-negative value.
* @since 1.2
*/
public TolerantIntegerComparison isWithin(int tolerance) {
return new TolerantIntegerComparison() {
@Override
public void of(int expected) {
Integer actual = IntegerSubject.this.actual;
checkNotNull(
actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected);
checkTolerance(tolerance);

if (!equalWithinTolerance(actual, expected, tolerance)) {
failWithoutActual(
fact("expected", Integer.toString(expected)),
butWas(),
fact("outside tolerance", Integer.toString(tolerance)));
}
}
};
}

/**
* Prepares for a check that the subject is a number not within the given tolerance of an expected
* value that will be provided in the next call in the fluent chain.
*
* @param tolerance an exclusive lower bound on the difference between the subject and object
* allowed by the check, which must be a non-negative value.
* @since 1.2
*/
public TolerantIntegerComparison isNotWithin(int tolerance) {
return new TolerantIntegerComparison() {
@Override
public void of(int expected) {
Integer actual = IntegerSubject.this.actual;
checkNotNull(
actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected);
checkTolerance(tolerance);

if (equalWithinTolerance(actual, expected, tolerance)) {
failWithoutActual(
fact("expected not to be", Integer.toString(expected)),
butWas(),
fact("within tolerance", Integer.toString(tolerance)));
}
}
};
}

/**
@@ -41,4 +144,9 @@ protected IntegerSubject(FailureMetadata metadata, @Nullable Integer integer) {
public final void isEquivalentAccordingToCompareTo(@Nullable Integer other) {
super.isEquivalentAccordingToCompareTo(other);
}

/** Ensures that the given tolerance is a non-negative value. */
private static void checkTolerance(int tolerance) {
checkArgument(tolerance >= 0, "tolerance (%s) cannot be negative", tolerance);
}
}
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import static com.google.common.truth.IterableSubject.ElementFactGrouping.FACT_PER_ELEMENT;
import static com.google.common.truth.SubjectUtils.accumulate;
import static com.google.common.truth.SubjectUtils.annotateEmptyStrings;
import static com.google.common.truth.SubjectUtils.asList;
import static com.google.common.truth.SubjectUtils.countDuplicates;
import static com.google.common.truth.SubjectUtils.countDuplicatesAndAddTypeInfo;
import static com.google.common.truth.SubjectUtils.countDuplicatesAndMaybeAddTypeInfoReturnObject;
@@ -36,7 +37,6 @@
import static com.google.common.truth.SubjectUtils.iterableToList;
import static com.google.common.truth.SubjectUtils.objectToTypeName;
import static com.google.common.truth.SubjectUtils.retainMatchingToString;
import static java.util.Arrays.asList;

import com.google.common.base.Function;
import com.google.common.base.Objects;
@@ -241,7 +241,7 @@ public final void containsAnyIn(@Nullable Iterable<?> expected) {
* fails.
*/
@SuppressWarnings("AvoidObjectArrays")
public final void containsAnyIn(Object[] expected) {
public final void containsAnyIn(@Nullable Object[] expected) {
containsAnyIn(asList(expected));
}

@@ -333,7 +333,7 @@ public void inOrder() {
*/
@CanIgnoreReturnValue
@SuppressWarnings("AvoidObjectArrays")
public final Ordered containsAtLeastElementsIn(Object[] expected) {
public final Ordered containsAtLeastElementsIn(@Nullable Object[] expected) {
return containsAtLeastElementsIn(asList(expected));
}

Loading