### Question:
TopHatFunction implements Function<Double, Double> { @Override public Double apply(Double x) { ArgChecker.notNull(x, "x"); ArgChecker.isTrue(x != _x1, "Function is undefined for x = x1"); ArgChecker.isTrue(x != _x2, "Function is undefined for x = x2"); if (x > _x1 && x < _x2) { return _y; } return 0.; } TopHatFunction(double x1, double x2, double y); @Override Double apply(Double x);  }### Answer:
@Test public void testNull() { assertThatIllegalArgumentException() .isThrownBy(() -> F.apply((Double) null)); }
@Test public void testX1() { assertThatIllegalArgumentException() .isThrownBy(() -> F.apply(X1)); }
@Test public void testX2() { assertThatIllegalArgumentException() .isThrownBy(() -> F.apply(X2)); }
@Test public void test() { assertThat(F.apply(X1 - 1e-15)).isEqualTo(0); assertThat(F.apply(X2 + 1e-15)).isEqualTo(0); assertThat(F.apply((X1 + X2) / 2)).isEqualTo(Y); }