import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class User {
private final String name;
private final int age;
private final String email;
User(String name, int age, String email) {
this.name = name;
this.age = age;
this.email = email;
}
String getName() { return name; }
int getAge() { return age; }
String getEmail() { return email; }
}
public class UserTest {
@Test
void testUserProperties() {
User user = new User("Alice", 30, "alice@example.com");
assertAll("User properties",
() -> assertEquals("Alice", user.getName(), "Name should be Alice"),
() -> assertEquals(30, user.getAge(), "Age should be 30"),
() -> assertEquals("alice@example.com", user.getEmail(), "Email should be alice@example.com")
);
}
}This test defines a simple User class with three properties: name, age, and email.
In the testUserProperties() method, we create a User object with expected values.
We use assertAll to group three assertions. Each assertion checks one property using assertEquals.
Using lambda expressions inside assertAll ensures all assertions run, and if any fail, JUnit reports all failures together.
This approach helps quickly see all mismatches without stopping at the first failure.