truth

Fluent assertions for Java and Android

APACHE-2.0 License

Stars
2.7K
Committers
104

Bot releases are visible (Hide)

truth - Truth 0.41

Published by cpovirk over 6 years ago

  • Changed most of Truth's failure messages to a multi-line, key-value format. Provided an API for testing messages of this format. (4a510350)
  • Introduced the new API for building failure messages in a "key: value" format. See Subject.failWithActual and failWithoutActual, which use the new Fact class. (e06ca85f)
  • Changed the old API's failure messages to automatically add a "name: ..." field if the user called named(). In some cases, this adds a name where it was missing before; in others, it duplicates a name that is already present. The long-term fix for this will be to migrate to the new failure API, which always includes the name once, and possibly also to delete named() in favor of withMessage(). (911c9394)
  • Deprecated failWithRawMessageAndCause. Truth automatically attaches the cause if it's part of the assertion chain. If not, see the deprecation docs for the workaround. (3622e9cf)
  • Deprecated failComparing. Use check("foo").that(actual().foo()).isEqualTo(expectedFoo). (2db2a4fa)
  • Deprecated the remaining legacy fail* methods. (1f9b2d63daaae2ecc49f9cd4b87d1bd84c71ba04)
  • Hid protected method IterableSubject.failWithBadResultsAndSuffix() (5becbfe5).
  • Started throwing ComparisonFailure from MapSubject.containsEntry. (4330ec62)
  • Started throwing ComparisonFailure from assertThat(singleElementIterable).containsExactly(otherSingleElementIterable). (e44edd16)
  • Added code to remove Runner and Statement frames from the stack trace. (d2bb0743)
  • Added StringSubject.ignoringCase() (13e80543)
  • Added ignoringExtraRepeatedFieldElements() to ProtoTruth. (f0702044)
  • Added comparingExpectedFieldsOnly() to ProtoTruth. (08908c17)
  • Removed deprecated MultimapSubject.containsExactly(Multimap). Use containsExactlyEntriesIn(Multimap). (containsExactly(Object k0, Object v0, Object... rest) continues to exist.) (9c80ad50)
  • Removed deprecated isPartiallyOrdered() methods. Use isOrdered() (5becbfe5).
  • Started throwing UOE from IterableSubject.isNoneOf() and isNotIn(). (46c8d3d2)
  • Switched to Checker Framework @NullableDecl instead of jsr305 @Nullable. Tools that read these annotations may need to be updated to recognize the new annotation. (10ee459c)
truth - Truth 0.40

Published by cpovirk over 6 years ago

  • Added check(String template, Object... args). Most users of check() should migrate. If the new method doesn't suit your needs, please file a bug. (187a9699)
  • Removed getDisplaySubject(), and marked actualCustomStringRepresentation() as @ForOverride. Callers should use actualAsString(); overriders should use actualCustomStringRepresentation(). (47ea976e, 24d4c960)
  • Made assertThat(array).isEqualTo(otherArray) compare arrays contents (not array identity) even when the input wasn't statically known to be an array. (ece35ace)
  • Began cleaning stack traces from custom subjects outside of core Truth. (7a6f69d0)
  • Enhanced Expect to omit stack frames common to multiple failures. (48b31f74)
  • Put any user messages on their own lines, separate from the main failure message. (6d060b82)
  • Tweaked the format of array failure messages. (ece35ace)
  • Removed the type name from the output of arrays. (f4fabf2e)
  • For array subjects, made named() supplement the existing actual value text, not replace it. This brings it in line with other subjects' behaviors. (f4fabf2e)
  • Tweaked failure messages for array asList() assertions. (df5c101a)
  • Tweaked failure messages for isAnyOf, isNone, and isNotIn to be more consistent. (6233d1b5)
  • Changed Subject.fail(String, Object) to stop including class names if the Object's toString() representation matches the value under test's. (This is likely to be uncommon unless you are overriding isEqualTo(), in which case we recommend delegating to super.isEqualTo() when possible.) (7af9c567)
  • Stopped calling actual.equals(null); all objects are assumed to be not equal to null. (c1ab4ede)
  • Added displayingDiffsPairedBy to IterableOfProtosSubject. (a51fc7ad)
  • Add support for float and double comparisons in ProtoTruth. (6cd80683)
  • Check only the descriptor identity before comparing messages in ProtoSubject. (7df57902)
  • Add formatted diffs for ProtoTruth Correspondence comparisons. (4b790a30)
  • Removed deprecated (Object expected, double tolerance) overloads of isEqualTo() and isNotEqualTo(). (ca04f65b)
  • Added the @CompatibleWith annotation from http://errorprone.info to isSameAs, isNotSameAs, isAnyOf, and isNoneOf. (24876516)
  • Made assertThat(...).is{,Not}InstanceOf(SomeInterface.class) blow up with a helpful message under GWT, rather than always fail in the case of isInstanceOf and always succeed in the case of isNotInstanceOf. (026d9229)
  • Made assertThat(null).isInstanceOf(...) fail() under GWT instead of throw NullPointerException. (026d9229)
truth - Truth 0.39

Published by cpovirk almost 7 years ago

  • Changed FailureStrategy to a one-method interface: fail(AssertionError), removing AbstractFailureStrategy.
truth - Truth 0.38

Published by cpovirk almost 7 years ago

  • Added overloads to containsExactlyElementsIn() and similar methods to accept arrays.
  • Made Expect support concurrent calls to fail().
  • Truth is now built with -target 7. However, it continues to depend on only "Java-6-like" APIs so that it continues to work on old versions of Android. (16887362)
  • Worked around GWT's buggy handling of double[] equality. Also, changed the rendering of double[] values under GWT to more closely match Java. The change requires an API that isn't present in older browers, so please report any problems you encounter. (1a4c6797)
  • Made StandardSubjectBuilder.check() final. (1d44b587)
truth - Truth 0.37

Published by cpovirk almost 7 years ago

  • Delete Subject.failureStrategy. Use Subject.fail*.
  • Delete Truth.THROW_ASSERTION_ERROR and TruthJUnit.throwAssumptionError(). Use Truth.assert_() and TruthJUnit.assume() (and methods like fail() and about(...).that(...) on the resulting objects).
  • Delete SubjectFactory and CustomSubjectBuilderFactory. Use nested types Subject.Factory and CustomSubjectBuilder.Factory, which accept new type FailureMetadata rather than FailureStrategy.
  • Make some Subject constructors protected now that they're useful only from subclasses.
  • Prevent subclassing of DefaultSubject entirely: Use Subject.
  • Enhanced our stripping of stack traces.
truth - Truth 0.36

Published by cpovirk about 7 years ago

  • Delete the *Verb* types and associated classes (after migrating Proto-Truth).
  • Delete ExpectationGatherer.
  • Deprecate Subject.failureStrategy, introducing more Subject.fail* methods to take its place.
  • Deprecate Truth.THROW_ASSERTION_ERROR and TruthJUnit.throwAssumptionError(). Users should use Truth.assert_() and TruthJUnit.assume() (and methods like fail() and about(...).that(...) on the resulting objects).
  • Deprecate SubjectFactory and CustomSubjectBuilderFactory, introducing nested types Subject.Factory and CustomSubjectBuilder.Factory to take their place. The nested types accept new type FailureMetadata rather than FailureStrategy, and our Subject classes have been updated accordingly. The main benefit is that, once you update your Subject constructors to accept FailureMetadata, you can expose a Subject.Factory, and it can usually be implemented with a method reference: return FooSubject::new;.
truth - Truth 0.35

Published by cpovirk about 7 years ago

Maven Release

  • Remove withFailureMessage, the old name of withMessage.
  • Remove assertAbout(...).withFailureMessage(...) in favor of assertWithMessage(...).about(...).
  • Deprecate ExpectationGatherer.
  • Deprecate the *Verb* types in favor of new *SubjectBuilder* types.
  • Add subjects for IntStream and LongStream.
  • Add the no-arg MultimapSubject.containsExactly() method.
  • Call out empty strings more clearly in collection subjects' failure messages.
  • Make various subjects behave better when used with Expect. Primarily, make any given assertion call fail at most once.
  • In Expect, always output failed expectations, even if an exception is thrown, and always fail the test, even if the exception was expected. Also, always include a stack trace when one was requested, even if the assertion specifies an additional cause.
  • Upgrade Guava dependency. You might notice that we now depend on 22.0-android. Guava says to depend on the Android version because Truth is usable on both Android and the JRE. If Maven or another build tool starts to give you 22.0-android at runtime instead of the "normal" version of Guava, you can override it.
truth - Truth 0.34

Published by cpovirk over 7 years ago

Maven Release

  • Add MultimapSubject.containsExactly.
  • Remove the redundant synthetic cause from truth assertion errors.
  • Begin renaming withFailureMessage to withMessage (on AbstractVerb/TestVerb).
  • Deprecate assertAbout(...).withFailureMessage(...) in favor of assertWithMessage(...).about(...).
  • FailureStrategy is fully abstract. Users should prefer AbstractFailureStrategy or one of the alternatives detailed in the javadocs.
  • Lock down assorted APIs that aren't meant to be used / used publicly / subtyped.
truth - Truth 0.33

Published by cgruber over 7 years ago

Maven Release

Changes to existing Subjects and Core classes

  • [API] Introduce ExpectFailure, a common mechanism for capturing failures in Truth, allowing tests to verify Truth failures without catching AssertionError. Intended primarily for testing Subject implementations.
  • [API] Deprecate PrimitiveDoublesArraySubject.hasvaluesWithin() and
    PrimitiveFloatArraySubject.hasvaluesWithin().
  • [SPI] Introduce AbstractFailureStrategy; users creating their own custom FailureStrategy implementations are encouraged to migrate to this class if possible.
  • [SPI] Add Subject.ignoreCheck() which is similar to Subject.check() but passes a no-op failure strategy, to
    allow chaining to continue when non-short-circuiting failure strategies are used (such as Expect).
  • Restrict visibility of the Platform class, which was never intended to be part of the public API. Most usages can simply be removed / inlined, usages that require GWT compatibility should open feature requests.

Extensions

  • Protocol Buffers

    • Permit Iterables for field numbers, descriptors, and handles with the protocol buffers FieldScope APIs
    • Fix comparison rules for map fields.

Fixes

  • Typo in LiteProtoTruth docs
  • assertThat(Double.NaN).isNaN() in gwt/j2cl now working properly.
  • Variety of improvements to error messages in MultimapSubject and MapSubject
  • ThrowableSubject and Java8 Optional*Subject tests now use ExpectFailure which exposed some bad behavior, now fixed.
  • IterableSubject adds type information to errors when string representations are the same, to clarify some
    ambiguous cases

Misc

  • Internal clean-up of FailureStrategy usage to prepare for FailureStrategy becoming fully abstract
  • Source now formatted via google-java-format
  • For users of ErrorProne, add @SuppressWarnings("TruthSelfEquals") since Truth tests sometimes need to
    test equality against the same reference to prove behavior. Generally ErrorProne will flag that as an error,
    since it can never fail (and is therefore usually a badly written test)
  • Some docs on OptionalSubject updated relating to complex assertions.
  • Fix some sample code containing a bug.

For details, see the complete list of included commits.

truth - Truth 0.32

Published by cgruber over 7 years ago

Maven Release

New Subjects

  • OptionalIntSubject (in java8 extension)
  • StreamSubject (in java8 extension)

Changes to existing Subjects and Core classes

  • add .hasValueThat() methods to primitive optionals which chain to the appropriate subject
  • ThrowableSubject.hasMessageThat() which chains to StringSubject, in place of hasMessage(String)
  • ThrowableSubject.hasCauseThat() which chains to ThrowableSubject around the cause
  • make isInstanceof() and related methods abort hard, under -XdisableClassMetadata.
  • Introduce DelegatedVerbFactory as a more powerful (but looser) alternative to SubjectFactory
  • make MultimapSubject use usingCorrespondence() to allow custom "Fuzzy" equality for contains ops.
  • Allow usingExactEquality on floating point subjects take Number subtypes, not just floating point types.
  • Allow one-arg isEqualTo() to be used for primitive arrays of floating point types, implementing an agreed
    upon algorithm
  • Add containsCell(Cell) and doesNotContainCell(Cell) to TableSubject.
  • Include more readable hexadecimals when isEqualTo fails on a byte[].

New Extensions

  • Protocol Buffers
    • Support for lite and heavy (with proto-reflection) protocol buffers
    • IterableProtoSubject

Fixes

  • Make asList() chaining methods obey named()

Misc

  • Code all formated with google-java-format
  • some error-prone notified improvemetns

For details, see the complete list of included commits.

truth - Truth 0.31

Published by cgruber over 7 years ago

Maven Release

New Subjects

  • SortedMapSubject and SortedSetSubject

Changes to existing Subjects and Core classes

  • Add GWT support to Java8 subjects
  • Lock down some of the Subject infrastructure, making several methods final
  • Add @SafeVarargs to some methods where appropriate
  • Depend on Guava 20.
  • More use of usingTolerance() for relevant Subjects
  • Various failure message improvements

New Extensions

  • Protocol Buffers
    • Support for lite and heavy (with proto-reflection) protocol buffers
    • IterableProtoSubject

For details, see the complete list of included commits.

truth - Truth 0.30

Published by cgruber about 8 years ago

Pushing towards a 1.0 release
Maven Release

New Subjects

  • OptionalSubject (for java.util.Optional, accessible via Truth8.assertThat(Optional<T>))
    (see details under "new extensions" below)

Changes to existing Subjects and Core classes

  • Preliminary versions of "Fuzzy Equality" for doubles/floats. See DoublesSubject for
    new APIs, and we'll be updating the docs on fuzzy equality soon.

    • Subject implementers should note changes to the Service Provider Interface (SPI) for writing
      custom Subject subclasses:
      • getSubject() -> actual()
      • getDisplaySubject() -> actualAsString()
      • If you want to provide a subject-specific string representation of the type being tested, a new
        method actualCustomStringRepresentation() can be overridden. The deprecated
        getDisplaySubject() and getSubject() methods should not be overridden (and will be
        deleted in Truth 1.0. The renamed methods are final.
        actualAsString() has logic that not only consumes the string representation (default or custom)
        but also honors .named() and other contextual formatting.
  • More evolution of "Fuzzy" truth - near-value approximation for certain types rather than strict
    equality is now supported by way of a "correspondence" mechanism, and the capabilities are
    being extended to many existing subjects.

    • To use:

          assertThat(actualIterable)
              .comparingElementsUsing(correspondence)
              .containsExactlyElementsIn(expectedIterable);
      

      Currently supports containsExactlyElementsIn(Iterable<E>), doesNotContain(E), and
      contains(E) methods. Subjects for Map, Iterable, and the Multimap types all support
      correspondence. For more detail, see the javadoc for IterableSubject.UsingCorrespondence and
      Correspondence

  • .named() now supports a varargs/format construction, such as:

          assertThat(someBooleanFunction())
              .named("processed %s(%s)", foo, bar)
              .isTrue();
    

    This results in a more suitable error message: Not true that processed foo(bar) <false> is true as
    compared with the default message, and requires less string concatenation where that may prove
    awkward

New Extensions

  • Add an extension for Java8 types, initially containing a subject forjava.util.Optional
    • Include "com.google.truth.extensions:truth-java8-extension:0.30" in your build dependencies

    • To use:

          import static com.google.common.truth.Truth8.assertThat;
          import java.util.Optional;
          public class MyTest {
            @Test public void testOptional() {
              Optional<String> o = Optional.of("Foo");
              assertThat(o).isPresent(); //succeeds
              assertThat(o).hasValue("Foo"); //succeeds
              assertThat(o).isEmpty(); // fails
            }
          }
      

Fixes

  • Fix a missing @Nullable in AbstractVerb.that(T)
  • Various cleanups of code, docs, readme, javadocs, and contribution
truth - Truth 0.29

Published by cgruber about 8 years ago

Pushing towards a 1.0 release
Maven Release

New Subjects

  • AtomicLongMapSubject

Changes to existing Subjects and Core classes

  • Preliminary versions of "Fuzzy Equality" for doubles/floats. See DoublesSubject for
    new APIs, and we'll be updating the docs on fuzzy equality soon.
  • Prefer isEqualTo instead of equals since that is a method with a fairly precise
    meaning in Java, and we were hijacking it. .equals() shouldn't be called on Subject
    implementations.
  • Multidimensional Array support in ObjectArraySubject
  • Lots of renames and deprecations.
  • SPI/API cleanup
    • marking a lot of subjects or their methods final, or noting where we can't
    • start making parts of the infrastructure more in line with the Open/Closed Principle
      (final methods, etc.)
    • stop storing "failure message" in the TestVerb, part 1

New Extensions

  • An extension/contrib submodule, for things we want to ship with Truth,
    but which may need to be separate artifacts, mostly due to dependency
    issues or general bloat. Including our first entry: RE2J

    Support for MessageLite protocol buffers is also in extensions, but not released
    in 0.29.

Fixes

  • Some cleanups of generics
  • Message improvements:
    • Trim some stack trace of the obvious truth frames, to make it clearer where the
      locus of error is. (i.e. who needs to see Subject.failComparing() in the stack trace?)
    • ThrowableSubject uses string comparision where reasonable (to take advantage of
      JUnit's ComparisonFailure)
    • fix BooleanSubject's handling of null in failure messaging
    • other message improvements

Miscellaneous

  • Apply @CheckReturnValue across a wide range of methods (on by default).
    • Users are _strongly_ advised to use error-prone in their builds, to ensure
      that this is checked, and the compiler errors out when people fail to call the
      following chained methods.
  • build and continuous test system fixes
  • more recent upstream dependencies
  • full formating of the codebase using google-java-format
  • various improvements from error-prone
  • improvements to the examples
  • more flesh out some holes in the tests

Note: various methods are being deprecated in preparation for 1.0. A penultimate
pre-1.0 release will be cut with those deprecated methods intact. Then a 1.0 will
be released with those methods removed. This should give people a chance to
get the 1.0 features and benefits, but have a nice transition phase.