result += s;
}
};
result = "";
Callbacks callbacks = new Callbacks();
callbacks.add( fn1 );
callbacks.fire( "foo" );
assertEquals(" f1: foo", result);
result = "";
callbacks.add( fn2 );
callbacks.fire( "bar" );
assertEquals(" f1: bar f2: bar", result);
result = "";
callbacks.remove( fn2 );
callbacks.fire( "foobar" );
assertEquals(" f1: foobar", result);
result = "";
callbacks.add( fn1 );
callbacks.fire( "foo" );
assertEquals(" f1: foo f1: foo", result);
result = "";
callbacks = new Callbacks("unique");
callbacks.add( fn1 );
callbacks.add( fn1 );
callbacks.fire( "foo" );
assertEquals(" f1: foo", result);
result = "";
callbacks.add( fn3 );
callbacks.fire( "bar" );
assertEquals(" f1: bar f3_success: bar", result);
result = "";
callbacks = new Callbacks("memory");
callbacks.add( fn1 );
callbacks.fire( "foo" );
callbacks.add( fn2 );
callbacks.fire( "bar" );
callbacks.remove(fn2);
callbacks.fire( "foobar" );
assertEquals(" f1: foo f2: foo f1: bar f2: bar f1: foobar", result);
result = "";
callbacks = new Callbacks("stopOnFalse");
callbacks.add( fn1 );
callbacks.add( fn2 );
callbacks.fire( "bar" );
assertEquals(" f1: bar", result);
result = "";
callbacks.disable();
callbacks.fire( "bar" );
assertEquals("", result);
result = "";
callbacks = new Callbacks("memory once unique");
callbacks.add( fn1 );
callbacks.add( fn1 );
callbacks.fire( "bar" );
assertEquals(" f1: bar", result);
callbacks.fire( "foo" );
assertEquals(" f1: bar", result);
callbacks.add( fn2 );
callbacks.add( fn2 );
assertEquals(" f1: bar f2: bar f2: bar", result);
callbacks.remove( fn1 );
callbacks.add( fn1 );
assertEquals(" f1: bar f2: bar f2: bar f1: bar", result);
callbacks.remove( fn1 );
callbacks.disable();
callbacks.add( fn1 );
assertEquals(" f1: bar f2: bar f2: bar f1: bar f1: bar", result);
// Test adding callback functions in nested executions
result = "";
final Callbacks callbacks2 = new Callbacks("memory once unique");
callbacks2.add(fn1);
callbacks2.add(new Function(){public void f() {
callbacks2.add( fn2 );
}});
callbacks2.fire("foo");
assertEquals(" f1: foo f2: foo", result);
}