static private <T> Promise<?> testNaN(final Eventual _, final T x) throws Exception { final Promise<T> p = ref(x); check(p.equals(p)); check(!p.equals(ref(x))); try { p.call(); check(false); } catch (final ArithmeticException e) { /* expected */ } class ENaN extends Do<T,Promise<Boolean>> implements Serializable { static private final long serialVersionUID = 1L; public Promise<Boolean> fulfill(final T arg) throws Exception { throw new Exception(); } public Promise<Boolean> reject(final Exception reason) throws Exception { if (reason instanceof ArithmeticException) { return ref(true); } throw reason; } } final Promise<?> a = _.when(p, new ENaN()); final Promise<?> b = _.when(x, new ENaN()); final Promise<?> c = _.when(new Sneaky<T>(x), new ENaN()); return join(_, a, b, c); }
/** * Tests promises for a normal reference. */ static private <T extends Receiver<?>> Promise<?> testNormal(final Eventual _, final T x) throws Exception { final Promise<T> p = ref(x); check(p.equals(p)); check(ref(x).equals(p)); check(x.equals(p.call())); class EQ extends Do<T,Promise<Boolean>> implements Serializable { static private final long serialVersionUID = 1L; public Promise<Boolean> fulfill(final T arg) throws Exception { check(x.equals(arg)); return ref(true); } } final Promise<?> a = _.when(p, new EQ()); final Promise<?> b = _.when(x, new EQ()); final Promise<?> c = _.when(new Sneaky<T>(x), new EQ()); final T x_ = _._(x); check(x_.equals(x_)); check(_._(x_).equals(x_)); check(_._(x).equals(x_)); check(ref(x_).equals(p)); final Promise<?> d = _.when(x_, new EQ()); return join(_, a, b, c, d); }
/** * Tests promises for {@link Float}. */ static private Promise<?> testFloat(final Eventual _) throws Exception { // check normal handling final Promise<Float> pMin = ref(Float.MIN_VALUE); check(pMin.equals(pMin)); check(ref(Float.MIN_VALUE).equals(pMin)); check(Float.MIN_VALUE == pMin.call()); class EQ extends Do<Float,Promise<Boolean>> implements Serializable { static private final long serialVersionUID = 1L; public Promise<Boolean> fulfill(final Float arg) throws Exception { check(Float.MIN_VALUE == arg); return ref(true); } } final Promise<?> a = _.when(pMin, new EQ()); final Promise<?> b = _.when(Float.MIN_VALUE, new EQ()); final Promise<?> c = testNaN(_, Float.NaN); final Promise<?> d = testNaN(_, Float.NEGATIVE_INFINITY); final Promise<?> e = testNaN(_, Float.POSITIVE_INFINITY); return join(_, a, b, c, d, e); }