PortRanges { @SuppressWarnings("rawtypes") public static void init() { if (initialized.compareAndSet(false, true)) { TypeCoercions.registerAdapter(Integer.class, PortRange.class, new Function<Integer,PortRange>() { @Override public PortRange apply(Integer x) { return fromInteger(x); } }); TypeCoercions.registerAdapter(String.class, PortRange.class, new Function<String,PortRange>() { @Override public PortRange apply(String x) { return fromString(x); } }); TypeCoercions.registerAdapter(Iterable.class, PortRange.class, new Function<Iterable,PortRange>() { @Override public PortRange apply(Iterable x) { return fromIterable(x); } }); } }  static PortRange fromInteger(int x); static PortRange fromIterable(Iterable<?> c); static PortRange fromString(String s); @SuppressWarnings("rawtypes") static void init(); static final int MAX_PORT; static final PortRange ANY_HIGH_PORT; }
@Test public void testCoercion() { PortRanges.init(); PortRange r = TypeCoercions.coerce("80", PortRange.class); assertContents(r, 80); }
@Test public void testCoercionInt() { PortRanges.init(); PortRange r = TypeCoercions.coerce(80, PortRange.class); assertContents(r, 80); }