import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Assertions;
public class AssertAll {
native @Nullable String readNullable();
void test() {
String s1 = readNullable();
String s2 = readNullable();
String s3 = readNullable();
String s4 = readNullable();
Assertions.assertAll(
() -> Assertions.assertNotNull(s1),
() -> Assertions.assertTrue(s1.trim().isEmpty()),
null
);
Assertions.assertNotNull(s2);
Assertions.assertAll(
readNullable(), // message
() -> Assertions.assertTrue(s1.trim().isEmpty()),
() -> Assertions.assertTrue(s1.trim().isEmpty()),
() -> Assertions.assertTrue(s2.trim().isEmpty()),
() -> Assertions.assertTrue(s3.trim().isEmpty()),
() -> Assertions.assertTrue(s4.trim().isEmpty())
);
for (int i = 0; i < 100; i++) {
Assertions.assertAll(
() -> Assertions.assertTrue(s1.trim().isEmpty()),
() -> Assertions.assertTrue(s2.trim().isEmpty()),
() -> Assertions.assertTrue(s3.trim().isEmpty()),
() -> Assertions.assertTrue(s4.trim().isEmpty())
);
}
}
interface Person {
String getFirstName();
String getLastName();
}
void testNested(Person person) {
Assertions.assertAll("properties",
() -> {
String firstName = person.getFirstName();
Assertions.assertNotNull(firstName);
Assertions.assertAll("first name",
() -> Assertions.assertTrue(firstName.startsWith("J")),
() -> Assertions.assertTrue(firstName.endsWith("n"))
);
},
() -> {
String lastName = person.getLastName();
Assertions.assertNotNull(lastName);
Assertions.assertAll("last name",
() -> Assertions.assertTrue(lastName.startsWith("D")),
() -> Assertions.assertTrue(lastName.endsWith("e"))
);
}
);
}
void testEmpty() {
Assertions.assertAll();
}
}