added test for Enum.values()

This commit is contained in:
Renaud Pawlak 2017-05-11 07:46:01 +02:00
parent 3f5fd896ae
commit 6341b398d6

View File

@ -1,9 +1,21 @@
package source.enums;
import java.util.HashMap;
import java.util.Map;
public class ComplexEnumsWithInterface {
private final static Map<Integer, DayOfWeek> ORDINAL_MAP = new HashMap<>();
public static DayOfWeek fromPersistenceValue(Integer value) {
return ORDINAL_MAP.get(value);
}
public static void main(String[] args) {
DayOfWeek day = DayOfWeek.Wednesday;
assert day.persistenceValue == 3;
for (DayOfWeek c : DayOfWeek.values()) {
ORDINAL_MAP.put(c.persistenceValue, c);
}
assert ORDINAL_MAP.get(1) == DayOfWeek.Monday;
}
}