In this release, our assertions on Java 8 types continue to move from the Truth8 class to the main Truth class. This change should not break compatibility for any supported JDK or Android version, even users who test under old versions of Android without API desugaring. Additionally, we will never break binary compatibility, though some users will have to make changes to their source code in order for it to compile against newer versions.
This release is likely to lead to more build failures than 1.3.0 did. However, those failures should be straightforward to fix.
Example build failure
Foo.java:152: error: reference to assertThat is ambiguous
assertThat(repo.findFileWithName("foo")).isNull();
^
both method assertThat(@org.jspecify.nullness.Nullable Path) in Truth8 and method assertThat(@org.jspecify.nullness.Nullable Path) in Truth match
Simplest upgrade strategy (if you can update all your code atomically in the same commit as the Truth upgrade)
In the same commit:
Upgrade Truth to 1.4.0.
Replace import static com.google.common.truth.Truth8.assertThat; with import static com.google.common.truth.Truth.assertThat;.
If you use Kotlin, replace import com.google.common.truth.Truth8.assertThat with import com.google.common.truth.Truth.assertThat.
Replace import com.google.common.truth.Truth8; with import com.google.common.truth.Truth;.
again, similarly for Kotlin if needed
Replace remaining references to Truth8 with references to Truth.
For example, replace Truth8.assertThat(optional).isPresent() with Truth.assertThat(optional).isPresent().
If you're feeling lucky, you can try this one-liner for the code updates:
After that process, it is possible that you'll still see build errors from ambiguous usages of assertThat static imports. If so, you can find a workaround in the section about overload ambiguity in the release notes for 1.3.0. Alternatively, you can wait to upgrade until after a future Truth release, which will eliminate the ambiguity by changing the signatures of some Truth.assertThat overloads.
Incremental upgrade strategy
If you have a very large repo or you have other reasons to prefer to upgrade incrementally, you can use the approach that we used inside Google. Roughly, that approach was:
Make the optional changes discussed in the release notes for 1.3.0.
For any remaining calls to Truth8.assertThat, change them to avoid static import.
That is, replace assertThat(optional).isPresent() with Truth8.assertThat(optional).isPresent().
Upgrade Truth to 1.4.0.
Optionally replace references to Truth8 with references to Truth (including restoring static imports if desired), as discussed in section about the simple upgrade strategy above.
Optional additional changes
If you use assertWithMessage(...).about(intStreams()).that(...), expect.about(optionalLongs()).that(...), or similar, you can remove your call to about. This change will never be necessary; it is just a simplification.
This is similar to a previous optional change from 1.3.0, except that 1.3.0 solved this problem for streams and optionals, whereas 1.4.0 solves it for the other Truth8 types.
Updates com.google.truth.extensions:truth-java8-extension from 1.1.3 to 1.4.0
You can trigger a rebase of this PR by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Note
Automatic rebases have been disabled on this pull request as it has been open for over 30 days.
Bumps
truth
from 1.1.3 to 1.4.0. Updatescom.google.truth:truth
from 1.1.3 to 1.4.0Release notes
Sourced from com.google.truth:truth's releases.
... (truncated)
Commits
Updates
com.google.truth.extensions:truth-java8-extension
from 1.1.3 to 1.4.0You can trigger a rebase of this PR by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show