Skip to content

Commit

Permalink
Explain how to integrate with AssertJ soft assertions in README
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaldvogel authored and rpost committed Jan 5, 2024
1 parent c105d67 commit 6f2812b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,42 @@ It is possible to customize path where validation files are stored, in order to
* Register implemented configuration via Java Service Provider interface (namely: put fully qualified configuration class name in `resources/META-INF/services/de.cronn.assertions.validationfile.config.Configuration`)
## Soft Assertions
File based validation can be combined with [AssertJ’s soft assertions][assertj_soft_assertions].
### Example
```java
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import de.cronn.validationfile.junit5.JUnit5ValidationFileAssertions;
@ExtendWith(SoftAssertionsExtension.class)
class MyTest implements JUnit5ValidationFileAssertions {
@InjectSoftAssertions
private SoftAssertions softly;
@Override
public FailedAssertionHandler failedAssertionHandler() {
return callable -> softly.check(callable::call);
}
@Test
void myTestMethod() {
assertWithFileWithSuffix("actual value 1", "file1");
assertWithFileWithSuffix("actual value 2", "file2");
}
}
```

## See also

* [Intellij plugin for validation file comparison][intellij_plugin]

[meld]: https://meldmerge.org/
[intellij_plugin]: https://plugins.jetbrains.com/plugin/12931-validation-file-comparison
[assertj_soft_assertions]: https://assertj.github.io/doc/#assertj-core-soft-assertions
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.cronn.assertions.validationfile.sample;

import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import de.cronn.assertions.validationfile.junit5.JUnit5ValidationFileAssertions;

@Disabled("Enable to demonstrate how soft assertions work")
@ExtendWith(SoftAssertionsExtension.class)
class ValidationFileWithSoftAssertionsSampleTest implements JUnit5ValidationFileAssertions {

@InjectSoftAssertions
private SoftAssertions softly;

@Override
public FailedAssertionHandler failedAssertionHandler() {
return callable -> softly.check(callable::call);
}

@Test
void testSoftAssertions() throws Exception {
assertWithFileWithSuffix("actual1", "file1");
assertWithFileWithSuffix("actual2", "file2");
}

}

0 comments on commit 6f2812b

Please sign in to comment.