Comments (9)
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.
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.
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.
@jcgay no time for the moment to finish this, your commit (jcgay@88e9b96) seems almost finished :)
from assertj.
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.
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.
Agree !
Let's go for: hasCauseInstanceOf
and hasCauseExactlyInstanceOf
from assertj.
Thanks Jean Christophe, very nice work !
You also added some examples for assertj-examples, much appreciated.
from assertj.
Yep I forgot the examples the other time :)
Thanks !
from assertj.
Related Issues (20)
- Add default recursive comparison configuration for non accessible classes and fields HOT 6
- `extracting(Function...)` propagates `Object` instead of the common base type of all extractors HOT 6
- NPE with `extracting(Function... extractors)` HOT 3
- AssertJ: issue with Assertions.assertThat().usingRecursiveComparison().isEqualTo() HOT 6
- Provide reason and possible replacement for @Deprecated HOT 3
- AssertJ string assertions not working with Spock 2.3 and Groovy HOT 15
- isEqualTo on date can lead to unexpected failures when switching time zones HOT 1
- `InstanceOfAssertFactories.array` and `InstanceOfAssertFactories.array2D` expect array type parameter instead of the one for their elements HOT 1
- `AbstractOptionalDoubleAssert.hasValue(double)` fails with NaN HOT 11
- Temporal type not available on assertThat HOT 2
- check both isGreaterThan isLessThan HOT 9
- Find a better name for `InstanceOfAssertFactory` and `InstanceOfAssertFactories`
- isInstanceOf() should issue a better failure message when the tested object is null
- ignoringFieldsOnlyLhsHas for usingRecursiveComparison HOT 1
- Comparable interfaces can't be checked with isGreater/isLess directly HOT 3
- skipIf(Predicate) HOT 2
- Add AbstractCharSequenceAssert#doesNotHaveAny(Leading|Trailing)Whitespaces HOT 4
- Add AbstractOptionalAssert#hasValueSatisfying accepting ThrowableConsumer HOT 2
- Add a `containsInOrder` for collections HOT 1
- Move to Java 17 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from assertj.