### Question:
CharsetPreference implements Comparable<CharsetPreference> { static int round(final double weight) { Preconditions.checkArgument(weight>=0D,"Weight must be greater than or equal to 0 (%s)",weight); Preconditions.checkArgument(weight<=1D,"Weight must be lower than or equal to 1 (%s)",weight); return DoubleMath.roundToInt(weight*MAX_WEIGHT_DOUBLE,RoundingMode.DOWN); } CharsetPreference(final String charset, final int weight); String charset(); double weight(); boolean isWildcard(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); @Override int compareTo(final CharsetPreference o); static CharsetPreference valueOf(final String str); static CharsetPreference wildcard(); static CharsetPreference wildcard(final double weight); static CharsetPreference create(final Charset charset); static CharsetPreference create(final Charset charset, final double weight);  }### Answer:
@Test public void testRound$happyPath() throws Exception { assertThat(CharsetPreference.round(0.5001D),equalTo(500)); }
@Test public void testRound$lowerThanZero() throws Exception { try { CharsetPreference.round(-1D); fail("Should not round weights lower than 0"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Weight must be greater than or equal to 0 (-1.0)")); } }
@Test public void testRound$greaterThanOne() throws Exception { try { CharsetPreference.round(1.1D); fail("Should not round weights greater than 1"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Weight must be lower than or equal to 1 (1.1)")); } }