Truth 0.45
We are pushing hard to release a Truth 1.0 by June 30, after which we don't expect to remove any more APIs. Thanks for your patience with both our slow progress over the past several years and our rapid churn now.
To use the migration tools below, you'll need to set up Error Prone and configure our tools as plugins to run in patch mode.
Deletions:
- Removed deprecated
Subject.isSameAs
andisNotSameAs
. UseisSameInstanceAs
andisNotSameInstanceAs
, which are equivalent. (36200e6) - Hid the constuctor of
Correspondence
. Use the class's static factory methods instead. The most mechanical migration is usually toCorrespondence.from
. To help with migration, we're releasedCorrespondenceSubclassToFactoryCall
. (11da1ca) - Removed deprecated
Subject.fail*
methods. SeeSubject.failWithActual
andfailWithoutActual
, which use the newFact
class. To help with migration, we're releasedFailWithFacts
(and alsoImplementAssertionWithChaining
, which is also sometimes useful for these migrations), though you will likely need to make manual changes, as well. (36200e6) - Removed deprecated no-arg
Subject.check()
. Use the overload that accepts a description. (To help with this migration, we have addedProvideDescriptionToCheck
to Error Prone -- but then removed it before it became part of a release, so you'll need to pull it in manually.) (36200e6) - Removed deprecated
MathUtil
. For similar static methods, see Guava'sDoubleMath.fuzzyEquals
. But callers from customSubject
implementations may prefer an approach likecheck("score()").that(actual.score()).isWithin(tolerance).of(expected)
. (7b2876d) - Removed deprecated
createAndEnableStackTrace()
. Usecreate()
, which now also enables stack traces. (9362f4c)
Deprecations:
- Deprecated
isOrdered()
andisStrictlyOrdered()
. UseisInOrder()
andisInStrictOrder()
, which are equivalent. (146080a, 386207d) - Deprecated
containsAll*
on ProtoTruth,*StreamSubject
, andPrimitive*ArraySubject.*ArrayAsIterable
. UsecontainsAtLeast*
, which is equivalent. (82c1f2d, 386207d) - Deprecated
Subject.actual()
. Instead of calling it, declare your own field to store the actual value. To automate most migrations, we've providedStoreActualValueInField
. (297c0f1) - Deprecated
Subject.named
. Instead ofassertThat(foo).named("foo")
, useassertWithMessage("foo").that(foo)
. For custom subjects, useassertWithMessage("foo").about(foos()).that(foo)
. For other scenarios, see this FAQ entry about adding messages. To automate most migrations, we've providedNamedToWithMessage
(and a quick-and-dirty regex version for common cases). You might be interested in our notes from the API Review of this decision. (08afb24) - "Deprecated" the type parameters on
Subject
. To prepare for their removal in the next release, you can edit your code today to refer to the rawSubject
type. (KotlinSubject
authors, see below.) Also "deprecated" the self-type parameter onComparableSubject
. Again, you can prepare your code by referring to rawComparableSubject
(and later change it to refer toComparableSubject<T>
when the class has only one type parameter next release). Similarly, "deprecated" the type parameters onProtoSubject
andLiteProtoSubject
, along with most of the type parameters ofIterableOfProtosSubject
,MapWithProtoValuesSubject
, andMultimapWithProtoValuesSubject
. (21c29f7, 5abd9ed) - Loosened type parameters on
Subject.Factory
. This permits customSubject
subclasses extend rawSubject
instead ofSubject<FooSubject, Foo>
to prepare for when we remove the type parameters fromSubject
entirely. - Deprecated
DefaultSubject
. Use plainSubject
. (7b5311b) - Deprecated
SortedMapSubject
andSortedSetSubject
. Users will have to perform assertions directly on the result of methods likefirstKey
. We haven't found sufficient demand for the classes to keep them. (46aebcf) - Deprecated the
SetMultimap
-specific andListMultimap
-specificSubjects
, which add little to the generalMultimap
subjects. (2103fee) - Deprecated
actualAsString()
andinternalCustomName()
. They exist primarily to supportnamed()
, which is being removed. (d69ba29)
Other migration notes:
- The order in which you migrate can be important: Migrate off
actual()
andnamed()
before removing type parameters from customSubject
classes. - The tool we'll release for migrating off
named
requires that customSubject
classes expose aSubject.Factory
, as described in our docs about extensions. - To remove the type parameters from
Subject
subclasses, you can get most of the way there with a Perl-compatible regex search-and-replace operation:s/\bSubject<([^<>]*|[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*>[^<>]*<[^<>]*>[^<>]*|[^<>]*<[^<>]*<[^<>]*>[^<>]*>)>/Subject/g
Features:
- For very simple tests, failure messages will include a "value of:" line. For example, the failure message of
assertThat(fetchLogMessages()).isEmpty()
might contain "value of: fetchLogMessages()." This feature is not available under Android or GWT, and it is only available if you have ASM on your classpath. - Exposed the constructors of
ThrowableSubject
,MapSubject
, andMultimapSubject
to subclasses. Note that actually extending those subjects won't fully work until we remove the type parameters fromSubject
. (1a39d5a, 32f76a5) - Temporarily made
DefaultSubject
extensible again. Kotlin subjects can now extendDefaultSubject
instead ofSubject
. This lets those subjects compile both before and after we remove the type parameters fromSubject
. After we remove the type parameters, Kotlin subjects should extendSubject
again (with no type parameters), as we'll later removeDefaultSubject
. (6e45b27) - Made ProtoTruth
Subject
classes extendIterableSubject
,MapSubject
, andMultimapSubject
. (1a39d5a). - Updated stack-trace cleaning to handle reflection under Java 9.