This test uses JUnit's @EnumSource to run the same test method for each value of an enum. It verifies that the enum values are correctly passed and processed in the test.
A. The test method parameter type does not match the enum type
B. @EnumSource cannot be used with Status enum
C. assertNotNull is not a valid assertion
D. The test method must be static
Solution
Step 1: Check parameter type vs enum type
@EnumSource(Status.class) passes enum constants of type Status, but method expects String parameter.
Step 2: Understand type mismatch impact
This causes a runtime error because JUnit cannot convert Status enum to String automatically.
Final Answer:
The test method parameter type does not match the enum type -> Option A
Quick Check:
Parameter type must match enum type = A [OK]
Hint: Method parameter type must be the enum type used in @EnumSource [OK]
Common Mistakes:
Using String instead of enum type as parameter
Thinking @EnumSource only works with strings
Assuming test method must be static
5.
You want to test only specific enum values OPEN and CLOSED from the enum TicketStatus { OPEN, IN_PROGRESS, CLOSED, REOPENED } using @EnumSource. Which is the correct way to do this?
hard
A. @EnumSource(TicketStatus.class, include = {OPEN, CLOSED})
B. @EnumSource(value = TicketStatus.class, names = {"OPEN", "CLOSED"})
C. @EnumSource(TicketStatus.class, only = {"OPEN", "CLOSED"})
D. @EnumSource(TicketStatus.class, filter = {OPEN, CLOSED})
Solution
Step 1: Recall how to filter enum values in @EnumSource
@EnumSource supports a 'names' attribute to specify which enum constants to include.
Step 2: Check each option's syntax
@EnumSource(value = TicketStatus.class, names = {"OPEN", "CLOSED"}) uses 'names' with string array correctly. Others use invalid or unsupported attributes.
Final Answer:
@EnumSource(value = TicketStatus.class, names = {"OPEN", "CLOSED"}) -> Option B
Quick Check:
Use 'names' to select enum values in @EnumSource = B [OK]
Hint: Use 'names' attribute with enum strings to filter values [OK]
Common Mistakes:
Using unsupported attributes like include or only
Passing enum constants instead of strings in names
Forgetting to specify value = Enum.class
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.