RequestParameter extends Parameter<String> { public <E extends Enum<E>> E toEnum(Class<E> type) { String value = toString(); try { return Enum.valueOf(type, value.toUpperCase()); } catch (Exception e) { throw new InvalidRequestParameterException(getName(), value); } } RequestParameter(String name, String value); boolean isBlank(); @Override boolean isEmpty(); @Override RequestParameter validateWith(ValidationStrategy<String> validationStrategy); @Override String toString(); String toString(String defaultValue); Double toDouble(); Double toDouble(double defaultValue); Long toLong(); Long toLong(long defaultValue); Integer toInteger(); Integer toInteger(int defaultValue); boolean toBoolean(); boolean toBoolean(boolean defaultValue); E toEnum(Class<E> type); E toEnum(Class<E> type, E defaultValue);  }
@Test public void testToEnumWithValidValues() throws Exception { assertEquals(AssetPackageMode.PRODUCTION, new RequestParameter(null, "PRODUCTION").toEnum(AssetPackageMode.class)); assertEquals(AssetPackageMode.PRODUCTION, new RequestParameter(null, "production").toEnum(AssetPackageMode.class)); assertEquals(AssetPackageMode.PRODUCTION, new RequestParameter(null, "Production").toEnum(AssetPackageMode.class)); }