Releases: google/truth
Truth 0.33
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 catchingAssertionError
. Intended primarily for testingSubject
implementations. - [API] Deprecate
PrimitiveDoublesArraySubject.hasvaluesWithin()
and
PrimitiveFloatArraySubject.hasvaluesWithin()
. - [SPI] Introduce
AbstractFailureStrategy
; users creating their own customFailureStrategy
implementations are encouraged to migrate to this class if possible. - [SPI] Add
Subject.ignoreCheck()
which is similar toSubject.check()
but passes a no-op failure strategy, to
allow chaining to continue when non-short-circuiting failure strategies are used (such asExpect
). - 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 Java8Optional*Subject
tests now useExpectFailure
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 forFailureStrategy
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 0.32
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 ofhasMessage(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 toSubjectFactory
- make
MultimapSubject
useusingCorrespondence()
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)
anddoesNotContainCell(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 obeynamed()
Misc
- Code all formated with google-java-format
- some error-prone notified improvemetns
For details, see the complete list of included commits.
Truth 0.31
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 0.30
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
methodactualCustomStringRepresentation()
can be overridden. The deprecated
getDisplaySubject()
andgetSubject()
methods should not be overridden (and will be
deleted in Truth 1.0. The renamed methods arefinal
.
actualAsString()
has logic that not only consumes the string representation (default or custom)
but also honors.named()
and other contextual formatting.
- Subject implementers should note changes to the Service Provider Interface (SPI) for writing
-
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 forMap
,Iterable
, and theMultimap
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 for
java.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 0.29
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 ofequals
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: RE2JSupport 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'sComparisonFailure
) - fix BooleanSubject's handling of
null
in failure messaging - other message improvements
- Trim some stack trace of the obvious truth frames, to make it clearer where the
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.
- Users are _strongly_ advised to use error-prone in their builds, to ensure
- 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.