*/
public void testAppend() {
delayTestFinish(DELAY_TEST_FINISH);
SimpleFooRequest fooCtx1 = req.simpleFooRequest();
SimpleFooProxy foo1 = fooCtx1.create(SimpleFooProxy.class);
SimpleBarRequest barCtx = fooCtx1.append(req.simpleBarRequest());
SimpleFooRequest fooCtx2 = barCtx.append(req.simpleFooRequest());
assertNotSame(fooCtx1, fooCtx2);
assertSame(foo1, barCtx.edit(foo1));
assertSame(foo1, fooCtx2.edit(foo1));
SimpleBarProxy foo2 = barCtx.create(SimpleBarProxy.class);
assertSame(foo2, fooCtx1.edit(foo2));
assertSame(foo2, fooCtx2.edit(foo2));
SimpleFooProxy foo3 = fooCtx2.create(SimpleFooProxy.class);
assertSame(foo3, fooCtx1.edit(foo3));
assertSame(foo3, barCtx.edit(foo3));
try {
// Throws exception because c3 has already accumulated some state
req.simpleValueContext().append(fooCtx2);
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException expected) {
}
try {
// Throws exception because a different RequestFactory instance is used
fooCtx2.append(createFactory().simpleFooRequest());
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException expected) {
}
// Queue up two invocations, and test that both Receivers are called
final boolean[] seen = {false, false};
fooCtx1.add(1, 2).to(new Receiver<Integer>() {
@Override
public void onSuccess(Integer response) {
seen[0] = true;
assertEquals(3, response.intValue());
}
});
barCtx.countSimpleBar().to(new Receiver<Long>() {
@Override
public void onSuccess(Long response) {
seen[1] = true;
assertEquals(2, response.longValue());
}
});
// It doesn't matter which context instance is fired
barCtx.fire(new Receiver<Void>() {
@Override
public void onSuccess(Void response) {
assertTrue(seen[0]);
assertTrue(seen[1]);
finishTestAndReset();