Assertj-core: Idea: complete AbstractAssert.as...() methods

Created on 26 Jun 2017  路  7Comments  路  Source: assertj/assertj-core

Hi,
just an idea, similar to AbstractAssert.asList(), AbstractAssert could have asOptional, asMap, ... returning the respective specialized Assertions instance.

I think this is particularly useful in combination with .extracting()

Most helpful comment

yes, seems this can be closed.

All 7 comments

Also, I wonder if asList() could be extended to take a class as argument like:

assertThat(listAsObject).asList(Integer.class).allMatch(v -> v > 10);

asList(Class) is something we can do but I'm worried adding all the other ones will clutter the API, especially if code completion shows assertion alphabetically, users will have to scroll after all asXXX methods to discover the API.

I'm ok to add the main ones as a per request basis (for example I would not add asBoolean )

I'm saying (more or less) the same thing in https://github.com/joel-costigliola/assertj-core/issues/167#issuecomment-33899613

How about changing the isInstanceOf & isExactlyInstanceOf signatures to cast?

Plus one to asMap().

I believe you have been heard in https://github.com/joel-costigliola/assertj-core/pull/1498 ;-)

Hi @tkruse, could you check if asInstanceOf satisfies your requirements?

yes, seems this can be closed.

Was this page helpful?
0 / 5 - 0 ratings