UDPAddressingModeConverter implements Converter<GMetric.UDPAddressingMode> { @Override public GMetric.UDPAddressingMode convertFrom(String value) { try { return GMetric.UDPAddressingMode.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new ParameterException("Couldn't convert value \"" + value + "\" to UDP addressing mode.", e); } }  @Override GMetric.UDPAddressingMode convertFrom(String value); @Override String convertTo(GMetric.UDPAddressingMode value);  }
@Test public void convertFromValidString() throws Exception { Assert.assertEquals(GMetric.UDPAddressingMode.MULTICAST, new UDPAddressingModeConverter().convertFrom("MULTICAST")); }
@Test public void convertFromValidLowerCaseString() throws Exception { assertEquals(GMetric.UDPAddressingMode.UNICAST, new UDPAddressingModeConverter().convertFrom("unicast")); }
@Test public void convertFromInvalidString() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert value \"Foobar\" to UDP addressing mode."); new UDPAddressingModeConverter().convertFrom("Foobar"); }
@Test public void convertFromNull() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert value \"null\" to UDP addressing mode."); new UDPAddressingModeConverter().convertFrom(null); }