Does AssertJ (or JUnit) have a way to chain, in a single (fluent) expression, several assertions on the same unit under test where one of the assertions may throw an exception. Essentially, I'm trying to assert that:
If a unit under test (X) doesn't result in a particular exception, which it may, then assert that a particular property on the unit under test doesn't hold. Otherwise assert the exception is of a certain type.
For example, is there a way to express the assertion that the following erroneous code could EITHER result in an Exception or in a situation where strings.size() != 10000:
@Test/*(expected=ArrayIndexOutOfBoundsException.class)*/
public void raceConditions() throws Exception {
List<String> strings = new ArrayList<>(); //not thread-safe
Stream.iterate("+", s -> s+"+")
.parallel()
.limit(10000)
//.peek(e -> System.out.println(e+" is processed by "+ Thread.currentThread().getName()))
.forEach(e -> strings.add(e));
System.out.println("# of elems: "+strings.size());
}
AssertJ has a concept of soft assertions, are those to be used in the scenarios like that? I'd appreciate some code samples if so.
Or perhaps there are better frameworks specifically design for this type of scenarios?
Thanks.