### Question:
EnumUtil { public static <K, T extends Enum<T> & Identifiable<K>> T getEnumById(Class<T> cls, K id, T defaultEnum) { for (T v : cls.getEnumConstants()) if (v.getId().equals(id)) return v; return defaultEnum; }  static T getEnumById(Class<T> cls, K id, T defaultEnum); @SuppressWarnings({ "rawtypes", "unchecked" }) static T getEnumById(Class<T> cls, K id); static T getEnumByIdString(Class<T> cls, String id); static T valueOf(Class<T> cls, String name, T defaultValue); @SuppressWarnings({ "rawtypes", "unchecked" }) static T valueOf(Class<T> cls, String name); static Enum<?> getDefaultValue(Class<Enum<?>> cls); static EnumSet<T> toEnumSet(long f, Class<T> cls); static long toLong(EnumSet<T> enums);  }### Answer:
@Test public void testGetEnumById() { assertSame(TestEnum.value1, TestEnum.get(1)); assertSame(TestEnum.value4, TestEnum.get(8)); assertSame(TestEnum.unknown, TestEnum.get(9)); assertSame(TestEnum.value3, EnumUtil.getEnumByIdString(TestEnum.class, "4")); assertSame(TestEnum.unknown, EnumUtil.getEnumByIdString(TestEnum.class, "100")); assertNull("Should return null if no defaultEnum is annotated and name doesn't match a value", EnumUtil.valueOf(TestEnumWithoutDefault.class, "unknown")); assertEquals("Should return default value annotated by JsonEnumDefaultValue if value doesn't match anyone", TestEnumWithJacksonAnnotation.value1, EnumUtil.valueOf(TestEnumWithJacksonAnnotation.class, "unknown")); }