### Question:
ImmutableQuality implements Quality { static ImmutableQuality create(final Type type, final double weight) { requireNonNull(type,"Quality type cannot be null"); checkQualityRange(weight, "Quality weight"); return new ImmutableQuality(weight, type); } private  ImmutableQuality(double value, Type type); @Override Type type(); @Override double weight(); @Override int compareTo(Quality that); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString();  }### Answer:
@Test public void cannotCreateInstancesWithNullType() throws Exception { try { ImmutableQuality.create(null,WEIGHT); fail("Should not create instances with null type"); } catch(NullPointerException e) { assertThat(e.getMessage(),equalTo("Quality type cannot be null")); } }
@Test public void cannotCreateInstancesWithInvalidWeight() throws Exception { try { ImmutableQuality.create(TYPE,-1D); fail("Should not create instances with invalid weight"); } catch(IllegalArgumentException e) { assertThat(e.getMessage(),equalTo("Quality weight cannot be negative (-1.0)")); } }
@Test public void twoQualitiesAreEqualIfBothTypeAndWeightAreEqual() { assertThat(VALUE,equalTo(ImmutableQuality.create(TYPE, WEIGHT))); }