assertj / assertj/assertj

AssertProvider not supported by SoftAssertions

Open
#2,817 5 comments 1 reaction 1 assignee Claimed by @scordio View on GitHub
theme: soft assertions
Dominant language
Java
Stars
2.8k
Forks
788
Avg merge
14h 57m
Merged PRs (30d)
36

Description

**Describe the bug**
It appears that it's not possible to use AssertProvider with SoftAssertions.assertThat

* assertj core version: 3.23.1
* java version: 8

**Test case reproducing the bug**

Add a test case showing the bug that we can run

```java
@Value
class Person {
int age;
}

class PersonContentAssert extends AbstractAssert {

protected PersonContentAssert(Person actual) {
super(actual, PersonContentAssert.class);
}

public PersonContentAssert hasAge(int age) {
// check that actual TolkienCharacter we want to make assertions on is not null.
isNotNull();
// check assertion logic
if (actual.getAge() != age) {
failWithMessage("Expected person's age to be <%s> but was <%s>", age, actual.getAge());
}
// return this to allow chaining other assertion methods
return this;
}
}
class PersonContent implements AssertProvider {
private final Person actual;

public PersonContent(Person actual) {
this.actual = actual;
}
@Override
public PersonContentAssert assertThat() {
return new PersonContentAssert(actual);
}
}

@Test
void providerTestWithoutSoftAssertions() {
Person person = new Person(84);
assertThat(new PersonContent(person)).hasAge(42);
}

@Test
void providerTestWithSoftAssertions() {
SoftAssertions softAssertions = new SoftAssertions();
Person person = new Person(84);
// softAssertions.assertThat(new PersonContent(person)).hasAge(42); // this does not compile
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.