Skip to content

Truth 0.45

Compare
Choose a tag to compare
@cpovirk cpovirk released this 30 May 15:00
· 640 commits to master since this release

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 and isNotSameAs. Use isSameInstanceAs and isNotSameInstanceAs, which are equivalent. (36200e6)
  • Hid the constuctor of Correspondence. Use the class's static factory methods instead. The most mechanical migration is usually to Correspondence.from. To help with migration, we're released CorrespondenceSubclassToFactoryCall. (11da1ca)
  • Removed deprecated Subject.fail* methods. See Subject.failWithActual and failWithoutActual, which use the new Fact class. To help with migration, we're released FailWithFacts (and also ImplementAssertionWithChaining, 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 added ProvideDescriptionToCheck 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's DoubleMath.fuzzyEquals. But callers from custom Subject implementations may prefer an approach like check("score()").that(actual.score()).isWithin(tolerance).of(expected). (7b2876d)
  • Removed deprecated createAndEnableStackTrace(). Use create(), which now also enables stack traces. (9362f4c)

Deprecations:

  • Deprecated isOrdered() and isStrictlyOrdered(). Use isInOrder() and isInStrictOrder(), which are equivalent. (146080a, 386207d)
  • Deprecated containsAll* on ProtoTruth, *StreamSubject, and Primitive*ArraySubject.*ArrayAsIterable. Use containsAtLeast*, 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 provided StoreActualValueInField. (297c0f1)
  • Deprecated Subject.named. Instead of assertThat(foo).named("foo"), use assertWithMessage("foo").that(foo). For custom subjects, use assertWithMessage("foo").about(foos()).that(foo). For other scenarios, see this FAQ entry about adding messages. To automate most migrations, we've provided NamedToWithMessage (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 raw Subject type. (Kotlin Subject authors, see below.) Also "deprecated" the self-type parameter on ComparableSubject. Again, you can prepare your code by referring to raw ComparableSubject (and later change it to refer to ComparableSubject<T> when the class has only one type parameter next release). Similarly, "deprecated" the type parameters on ProtoSubject and LiteProtoSubject, along with most of the type parameters of IterableOfProtosSubject, MapWithProtoValuesSubject, and MultimapWithProtoValuesSubject. (21c29f7, 5abd9ed)
  • Loosened type parameters on Subject.Factory. This permits custom Subject subclasses extend raw Subject instead of Subject<FooSubject, Foo> to prepare for when we remove the type parameters from Subject entirely.
  • Deprecated DefaultSubject. Use plain Subject. (7b5311b)
  • Deprecated SortedMapSubject and SortedSetSubject. Users will have to perform assertions directly on the result of methods like firstKey. We haven't found sufficient demand for the classes to keep them. (46aebcf)
  • Deprecated the SetMultimap-specific and ListMultimap-specific Subjects, which add little to the general Multimap subjects. (2103fee)
  • Deprecated actualAsString() and internalCustomName(). They exist primarily to support named(), which is being removed. (d69ba29)

Other migration notes:

  • The order in which you migrate can be important: Migrate off actual() and named() before removing type parameters from custom Subject classes.
  • The tool we'll release for migrating off named requires that custom Subject classes expose a Subject.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, and MultimapSubject to subclasses. Note that actually extending those subjects won't fully work until we remove the type parameters from Subject. (1a39d5a, 32f76a5)
  • Temporarily made DefaultSubject extensible again. Kotlin subjects can now extend DefaultSubject instead of Subject. This lets those subjects compile both before and after we remove the type parameters from Subject. After we remove the type parameters, Kotlin subjects should extend Subject again (with no type parameters), as we'll later remove DefaultSubject. (6e45b27)
  • Made ProtoTruth Subject classes extend IterableSubject, MapSubject, and MultimapSubject. (1a39d5a).
  • Updated stack-trace cleaning to handle reflection under Java 9.