Assertj-core: Implement assumeThat() static method to replace JUnit implementation

Created on 18 Apr 2017  路  4Comments  路  Source: assertj/assertj-core

Summary

I'd like to use all of the benefits of fluent assertJ style assertThat() method with assumeThat() method, with as it's couterpart in JUnit would through AssumptionViolatedException and allow to skip test execution on failed assumptions.

The reason is that I use that kind of assumptions pretty heavily and don't want to depend on JUnit specifically. There is great power in AssertJ already, and I'd like it to be available not just for assertions, but also for the assumptions.

Looks like this work was already initiated at org.assertj.swing.junit.util.Assumptions.assumeThat, but as for me it's proper place is in assertj-core library.

Example

assumeThat(someString).isNotBlank();

Java 8 specific ?

  • NO : create Pull Request from the 2.x branch

Most helpful comment

@falkoner good point about supporting conditions.
I'm ok to add this feature but we need to find a way to avoid hard dependency on JUnit (I might have idea for that).

All 4 comments

I definitely like the idea, I want to make sure though what the scope is (is that replicating all assertions in an assumeThat fashion ?) to avoid maintenance costs.

At bare minimum I'd go with what JUnit has:

static void assumeFalse(boolean b) 
static void assumeNoException(Throwable e) 
static void assumeNotNull(Object... objects) 
static void assumeNull(Object... objects)
static void assumeTrue(boolean b) 

Most importantly, ability to work with custom org.assertj.assertions.core.Condition in the fashion of is(), has(), and for collections - are(), allOf(), anyOf(), - will unlock assumeThat() for most purposes, and later based on usage we would be able to figure out which other methods are to be on priority list.

@falkoner good point about supporting conditions.
I'm ok to add this feature but we need to find a way to avoid hard dependency on JUnit (I might have idea for that).

Was this page helpful?
0 / 5 - 0 ratings