I am having below enum class
public enum EmployeeType {
PERMANENT("10"),
TEMPORARY("20"),
PART_TIME("30");
private final String employeeTypeId;
EmployeeType(final String employeeTypeId) {
this.employeeTypeId = employeeTypeId;
}
public String getEmployeeTypeId() {
return employeeTypeId;
}
}
Trying with below spec
class EmployeeTypeSpec extends Specification {
@Unroll
def "validate emp type"(EmployeeType employeeType) {
expect:
// want to assert each employeeType name() and employeeTypeId here
employeeType.name()
employeeType.employeeTypeId
where:
employeeType << EmployeeType.values()
}
}
Here, I am passing each enum values using values() method. but not sure how to assert the name and employeeTypeId for each enums?
CodePudding user response:
Something like this will probably end up making more sense than employeeType << EmployeeType.values()
:
def "Test enum values"() {
expect:
value.employeeTypeId == typeId
where:
// could have more columns here if the enum
// had more properties...
value | typeId
EmployeeType.PERMANENT | '10'
EmployeeType.TEMPORARY | '20'
EmployeeType.PART_TIME | '30'
}