joel-costigliola / assertj

AssertJ documentation
60 stars 30 forks source link

Improved Java 8 stream support for flatExtracting? #48

Closed GoGoris closed 8 years ago

GoGoris commented 8 years ago

Hi, at the moment I have this:

        assertThat(response.getSteps()).flatExtracting(input ->
                asList(input.getPeriod(),
                        input.getAmount(),
                        input.getNr())
        ).doesNotContain(0);

Would it be possible to support the following notations? Like extracting():

.flatExtracting(
                Step::getPeriod,
                Step::getAmount,
                Step::getNr
        )

Or accept a stream like flatMap()?

.flatExtracting(
        Stream.of(input.getPeriod(),
                        input.getAmount(),
                        input.getNr())
        )
PascalSchumacher commented 8 years ago

Hi GoGoris,

#extracting supports multiple Extractor parameters. So I think assertj should support the #flatExtracting(Step::getPeriod, Step::getAmount, Step::getNr) notation.

I tried to create a pull request with this features, but I could not figure out the correct generic signatures. :(

By the way, this repository is for the assertj website, please report further issues at https://github.com/joel-costigliola/assertj-core

Thanks! :)

PascalSchumacher commented 8 years ago

O.k. got it to work, but I'm not sure this results in easy readable tests. I would like to hear @joel-costigliola opinion on this, before investing the effort to come up with a polished pull request.

joel-costigliola commented 8 years ago

I think we can spike it and see how it goes, note that as you can extract different types the resulting list can only contain objects.

joel-costigliola commented 8 years ago

I have created https://github.com/joel-costigliola/assertj-core/issues/644 to track this issue. @PascalSchumacher do you need more feedback ? not sure that I have fully answered you.