Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve diagnosability for data signal mismatches in StepVerifier with a non-helpful toString() method #1558

Closed
mp911de opened this issue Mar 14, 2019 · 0 comments
Labels
type/enhancement A general enhancement
Milestone

Comments

@mp911de
Copy link

mp911de commented Mar 14, 2019

Currently, if an expectation for a data signal fails (StepVerifier.create(…).expectNext(foo)), the error message contains a toString() representation of the expected and the actual data item. This works very well if the class of the emitted item reports sufficient information to diagnose a mismatch (e.g. @Data classes, String, most java.lang types).

Some types (such as Java arrays, ByteBuffer) report information in their toString() method that aren't useful for further diagnosis:

expectation "expectNext(java.nio.HeapByteBuffer[pos=0 lim=7 cap=7])" failed (expected value: java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]; actual value: java.nio.HeapByteBuffer[pos=0 lim=7 cap=7])

It would be helpful to provide more insight to the actual payload, and ideally StepVerifier ships with formatters (ToStringFunction?) for common and well-known Java types that suffer from an informative toString() method.

I'm not sure that it makes a lot of sense to provide a user-configurable API because reactive code comes with a certain complexity and so does test code. We could continue writing test code mono.as(StepVerifier::as).withOptions(…) but I'm a bit torn regarding value vs. complexity.

@mp911de mp911de changed the title Improve diagnosability for data signal mismatches with a non-helpful toString() method Improve diagnosability for data signal mismatches in StepVerifier with a non-helpful toString() method Mar 14, 2019
@smaldini smaldini added the type/enhancement A general enhancement label Mar 26, 2019
@simonbasle simonbasle added this to the 3.3.0.RELEASE milestone Mar 27, 2019
@simonbasle simonbasle modified the milestones: 3.3.0.RELEASE, 3.3.0.M1 Apr 15, 2019
OlegDokuka pushed a commit to OlegDokuka/reactor-core that referenced this issue Apr 24, 2019
…ptions

This commit allows users to redefine `String` representation of various
objects that can be included in StepVerifier-produced messages:

 - added 2 new interfaces with implementations in ValueFormatters util
 - StepVerifierOptions can be set up with a single class-matching
 ToStringConverter, along with 0-n Extractors for container values
 - ErrorFormatter is now MessageFormatter
 - it has a more generic format(msg, arg...) method, which is preferred
 to String.format in the DefaultStepVerifier

In options, `getExtractors()` produces a copy of the user-defined
extractors to which it adds defaults at the end. Since only the first
matching extractor applies, this ensures that eg. adding an extractor
for `Integer[]` won't be superseded by the default Object[] extractor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants