Test Overview
This test verifies that an advanced data source correctly processes and returns complex data structures as expected.
This test verifies that an advanced data source correctly processes and returns complex data structures as expected.
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.Map; import java.util.List; class AdvancedDataSourceTest { @Test void testComplexDataHandling() { AdvancedDataSource source = new AdvancedDataSource(); Map<String, Object> data = source.getComplexData(); assertNotNull(data, "Data should not be null"); assertTrue(data.containsKey("users"), "Data should contain 'users' key"); Object usersObj = data.get("users"); assertTrue(usersObj instanceof List, "'users' should be a List"); List<?> users = (List<?>) usersObj; assertFalse(users.isEmpty(), "Users list should not be empty"); Object firstUser = users.get(0); assertTrue(firstUser instanceof Map, "Each user should be a Map"); Map<?, ?> userMap = (Map<?, ?>) firstUser; assertTrue(userMap.containsKey("id"), "User map should contain 'id'"); assertTrue(userMap.containsKey("name"), "User map should contain 'name'"); assertTrue(userMap.get("id") instanceof Integer, "User 'id' should be Integer"); assertTrue(userMap.get("name") instanceof String, "User 'name' should be String"); } } // Dummy class to illustrate class AdvancedDataSource { public Map<String, Object> getComplexData() { return Map.of( "users", List.of( Map.of("id", 1, "name", "Alice"), Map.of("id", 2, "name", "Bob") ) ); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | Create AdvancedDataSource instance | AdvancedDataSource object created | - | PASS |
| 3 | Call getComplexData() to retrieve data | Data returned: Map with key 'users' and list of user maps | assertNotNull(data) | PASS |
| 4 | Check data contains key 'users' | Data map keys: ['users'] | assertTrue(data.containsKey("users")) | PASS |
| 5 | Verify 'users' is a List | 'users' value is a List of user maps | assertTrue(usersObj instanceof List) | PASS |
| 6 | Check 'users' list is not empty | 'users' list size is 2 | assertFalse(users.isEmpty()) | PASS |
| 7 | Get first user from list | First user is a Map with keys 'id' and 'name' | assertTrue(firstUser instanceof Map) | PASS |
| 8 | Check user map contains 'id' and 'name' | User map keys: ['id', 'name'] | assertTrue(userMap.containsKey("id")) and assertTrue(userMap.containsKey("name")) | PASS |
| 9 | Verify 'id' is Integer and 'name' is String | User 'id' is Integer 1, 'name' is String 'Alice' | assertTrue(userMap.get("id") instanceof Integer) and assertTrue(userMap.get("name") instanceof String) | PASS |
| 10 | Test ends successfully | All assertions passed | - | PASS |