Test Overview
This test uses the Object Mother pattern to create a ready-to-use User object. It verifies that the User object created by the Object Mother has the expected default values.
This test uses the Object Mother pattern to create a ready-to-use User object. It verifies that the User object created by the Object Mother has the expected default values.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class User { private String name; private int age; public User(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } class UserObjectMother { public static User createDefaultUser() { return new User("Alice", 30); } } public class UserTest { @Test void testDefaultUserCreation() { User user = UserObjectMother.createDefaultUser(); assertEquals("Alice", user.getName()); assertEquals(30, user.getAge()); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initializes the test class UserTest | - | PASS |
| 2 | Calls UserObjectMother.createDefaultUser() to get a User object | User object with name 'Alice' and age 30 is created | - | PASS |
| 3 | Calls user.getName() and asserts it equals 'Alice' | User object is accessible with name 'Alice' | assertEquals("Alice", user.getName()) | PASS |
| 4 | Calls user.getAge() and asserts it equals 30 | User object is accessible with age 30 | assertEquals(30, user.getAge()) | PASS |
| 5 | Test completes successfully | All assertions passed | - | PASS |