@Test public void testAnnotationPrecedence() throws GuacamoleException { EnumGuacamoleProperty<Fish> favoriteFish = new EnumGuacamoleProperty<Fish>( "chinook", Fish.SALMON, "rainbow", Fish.TROUT ) { @Override public String getName() { return "favorite-fish"; } }; assertEquals(Fish.SALMON, favoriteFish.parseValue("chinook")); assertEquals(Fish.TROUT, favoriteFish.parseValue("rainbow")); try { favoriteFish.parseValue("salmon"); fail("Explicit key/value mapping should take priority over annotations."); } catch (GuacamoleException e) { } try { favoriteFish.parseValue("trout"); fail("Explicit key/value mapping should take priority over annotations."); } catch (GuacamoleException e) { } try { favoriteFish.parseValue("tuna"); fail("Annotations should not have any effect if explicit key/value mapping is used."); } catch (GuacamoleException e) { } }
@Override public T parseValue(String value) throws GuacamoleException { if (value == null) return null; T parsedValue = valueMapping.get(value); if (parsedValue != null) return parsedValue; List<String> legalValues = new ArrayList<>(valueMapping.keySet()); Collections.sort(legalValues); throw new GuacamoleServerException(String.format("\"%s\" is not a " + "valid value for property \"%s\". Valid values are: \"%s\"", value, getName(), String.join("\", \"", legalValues))); }
EnumGuacamoleProperty implements GuacamoleProperty<T> { @Override public T parseValue(String value) throws GuacamoleException { if (value == null) return null; T parsedValue = valueMapping.get(value); if (parsedValue != null) return parsedValue; List<String> legalValues = new ArrayList<>(valueMapping.keySet()); Collections.sort(legalValues); throw new GuacamoleServerException(String.format("\"%s\" is not a " + "valid value for property \"%s\". Valid values are: \"%s\"", value, getName(), String.join("\", \"", legalValues))); } }
EnumGuacamoleProperty implements GuacamoleProperty<T> { @Override public T parseValue(String value) throws GuacamoleException { if (value == null) return null; T parsedValue = valueMapping.get(value); if (parsedValue != null) return parsedValue; List<String> legalValues = new ArrayList<>(valueMapping.keySet()); Collections.sort(legalValues); throw new GuacamoleServerException(String.format("\"%s\" is not a " + "valid value for property \"%s\". Valid values are: \"%s\"", value, getName(), String.join("\", \"", legalValues))); } EnumGuacamoleProperty(Map<String, T> valueMapping);  EnumGuacamoleProperty(Class<T> enumClass);  EnumGuacamoleProperty(String key, T value, Object... additional); }
EnumGuacamoleProperty implements GuacamoleProperty<T> { @Override public T parseValue(String value) throws GuacamoleException { if (value == null) return null; T parsedValue = valueMapping.get(value); if (parsedValue != null) return parsedValue; List<String> legalValues = new ArrayList<>(valueMapping.keySet()); Collections.sort(legalValues); throw new GuacamoleServerException(String.format("\"%s\" is not a " + "valid value for property \"%s\". Valid values are: \"%s\"", value, getName(), String.join("\", \"", legalValues))); } EnumGuacamoleProperty(Map<String, T> valueMapping);  EnumGuacamoleProperty(Class<T> enumClass);  EnumGuacamoleProperty(String key, T value, Object... additional); @Override T parseValue(String value); }
EnumGuacamoleProperty implements GuacamoleProperty<T> { @Override public T parseValue(String value) throws GuacamoleException { if (value == null) return null; T parsedValue = valueMapping.get(value); if (parsedValue != null) return parsedValue; List<String> legalValues = new ArrayList<>(valueMapping.keySet()); Collections.sort(legalValues); throw new GuacamoleServerException(String.format("\"%s\" is not a " + "valid value for property \"%s\". Valid values are: \"%s\"", value, getName(), String.join("\", \"", legalValues))); } EnumGuacamoleProperty(Map<String, T> valueMapping);  EnumGuacamoleProperty(Class<T> enumClass);  EnumGuacamoleProperty(String key, T value, Object... additional); @Override T parseValue(String value);  }