Giter Site home page Giter Site logo

Comments (9)

jcgay avatar jcgay commented on July 20, 2024

Hi,

I wrote a test yesterday where I could benefit from using hasCause(), so I've tried implementing it.
It does what I need, but I'm not sure of what you've planned for this. As hasCause() there is using equals, the other assertion you proposed, hasCauseOfClass() seems necessary too. I feel that in most cases, we don't have access to exact reference of a Throwable to make assertions with ?

I will write hasCauseOfClass() to play with it and prepare a PR.
Thanks,

from assertj.

joel-costigliola avatar joel-costigliola commented on July 20, 2024

Yep, I think you are right, we don't usually have access to the cause exception instance so let's just keep these assertions :

hasCauseOfClass(Class<? extends Throwable> eClass);
hasRootCauseOfClass(Class<? extends Throwable> eClass);

or keep these but rename them to :

hasCause(Class<? extends Throwable> eClass);
hasRootCause(Class<? extends Throwable> eClass);

What do you think ?
I tend to prefer the second option but no strong opinion on that.

from assertj.

jcgay avatar jcgay commented on July 20, 2024

I prefer the second option too.

It seems that @twillouer (although I don't see his comment, I just received an email) has already done most of the work to match cause using class, so let's wait for it :)

from assertj.

twillouer avatar twillouer commented on July 20, 2024

@jcgay no time for the moment to finish this, your commit (jcgay@88e9b96) seems almost finished :)

from assertj.

joel-costigliola avatar joel-costigliola commented on July 20, 2024

One question though: do you think that hasCause(Class<? extends Throwable> eClass) should support inheritance ?
For example, if cause is a NullPointerException would hasCause(RuntimeException.class) be successful or not ?

I would say it should but it may be confusing ... WDYT ?

We may avoid the confusion by renaming the assertion to hasCauseInstanceOf(Class<? extends Throwable> eClass) and keep hasCause(Class<? extends Throwable> eClass) to check the exact runtime type.

from assertj.

jcgay avatar jcgay commented on July 20, 2024

I think it should support inheritance. Naming it hasCauseInstanceOf sounds good to me, it's consistent with isInstanceOf behavior.

Exposing another assertion to verify exact runtime type can be useful too but should we not call it something like hasCauseExactlyInstanceOf to keep the naming from AbstractAssert ?

from assertj.

joel-costigliola avatar joel-costigliola commented on July 20, 2024

Agree !

Let's go for: hasCauseInstanceOf and hasCauseExactlyInstanceOf

from assertj.

joel-costigliola avatar joel-costigliola commented on July 20, 2024

Thanks Jean Christophe, very nice work !
You also added some examples for assertj-examples, much appreciated.

from assertj.

jcgay avatar jcgay commented on July 20, 2024

Yep I forgot the examples the other time :)
Thanks !

from assertj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.