001 // Copyright 2007 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.waterken.bounce; 004 005 import static org.ref_send.promise.Eventual.near; 006 import static org.ref_send.test.Logic.join; 007 import static org.ref_send.test.Logic.was; 008 009 import java.io.Serializable; 010 011 import org.joe_e.array.ByteArray; 012 import org.joe_e.array.ConstArray; 013 import org.ref_send.list.List; 014 import org.ref_send.promise.Do; 015 import org.ref_send.promise.Eventual; 016 import org.ref_send.promise.Failure; 017 import org.ref_send.promise.Promise; 018 019 /** 020 * An argument passing test. 021 */ 022 public final class 023 Pitch { 024 private Pitch() {} 025 026 /** 027 * Runs a unit test. 028 * @param _ eventual operator 029 * @param x test subject 030 */ 031 static public Promise<?> 032 make(final Eventual _, final Wall x) { 033 final Wall x_ = _._(x); 034 035 class Re extends Do<ConstArray<AllTypes>,Promise<?>> 036 implements Serializable { 037 static private final long serialVersionUID = 1L; 038 039 public Promise<?> 040 fulfill(final ConstArray<AllTypes> a) { 041 return _.when(x_.bounce(a), was(a)); 042 } 043 } 044 final Promise<?> a = _.when(x_.getAll(), new Re()); 045 final Promise<?> b = 046 _.when(x_.bounce(near(Bounce.make(_).getAll())), new Re()); 047 048 final ByteArray payload = 049 ByteArray.array(new byte[] { 0,1,2,3,4,5,6,7,8,9 }); 050 final Promise<?> c = _.when(x_.bounce(payload), was(payload)); 051 052 final ByteArray maxPayload = 053 ByteArray.array(new byte[Failure.maxEntitySize]); 054 final Promise<?> d = _.when(x_.bounce(maxPayload), was(maxPayload)); 055 056 final Promise<?> e = _.when(x_.sum(1, 2, 3), was(6)); 057 058 return join(_, a, b, c, d, e); 059 } 060 061 // Command line interface 062 063 /** 064 * Executes the test. 065 * @param args ignored 066 * @throws Exception test failed 067 */ 068 static public void 069 main(final String[] args) throws Exception { 070 final List<Promise<?>> work = List.list(); 071 final Eventual _ = new Eventual(work.appender()); 072 final Promise<?> result = make(_, Bounce.make(_)); 073 while (!work.isEmpty()) { work.pop().call(); } 074 result.call(); 075 } 076 }