BroadcasterTestpublic class BroadcasterTest extends TestCase
Fields Summary |
---|
private static final int | MESSAGE_A | private static final int | MESSAGE_B | private static final int | MESSAGE_C | private static final int | MESSAGE_D |
Methods Summary |
---|
public void | test1()
/*
* One handler requestes one message, with a translation
*/
HandlerTester tester = new HandlerTester() {
Handler h;
public void go() {
Broadcaster b = new Broadcaster();
h = new H();
b.request(MESSAGE_A, h, MESSAGE_B);
Message msg = new Message();
msg.what = MESSAGE_A;
b.broadcast(msg);
}
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_B) {
success();
} else {
failure();
}
}
};
tester.doTest(1000);
| public void | test2()
/*
* 2 handlers request the same message, with different translations
*/
HandlerTester tester = new Tests2and3(2);
tester.doTest(1000);
| public void | test3()
/*
* 1000 handlers request the same message, with different translations
*/
HandlerTester tester = new Tests2and3(10);
tester.doTest(1000);
| public void | test4()
/*
* Two handlers request different messages, with translations, sending
* only one. The other one should never get sent.
*/
HandlerTester tester = new HandlerTester() {
Handler h1;
Handler h2;
public void go() {
Broadcaster b = new Broadcaster();
h1 = new H();
h2 = new H();
b.request(MESSAGE_A, h1, MESSAGE_C);
b.request(MESSAGE_B, h2, MESSAGE_D);
Message msg = new Message();
msg.what = MESSAGE_A;
b.broadcast(msg);
}
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
success();
} else {
failure();
}
}
};
tester.doTest(1000);
| public void | test5()
/*
* Two handlers request different messages, with translations, sending
* only one. The other one should never get sent.
*/
HandlerTester tester = new HandlerTester() {
Handler h1;
Handler h2;
public void go() {
Broadcaster b = new Broadcaster();
h1 = new H();
h2 = new H();
b.request(MESSAGE_A, h1, MESSAGE_C);
b.request(MESSAGE_B, h2, MESSAGE_D);
Message msg = new Message();
msg.what = MESSAGE_B;
b.broadcast(msg);
}
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_D && msg.getTarget() == h2) {
success();
} else {
failure();
}
}
};
tester.doTest(1000);
| public void | test6()
/*
* Two handlers request same message. Cancel the request for the
* 2nd handler, make sure the first still works.
*/
HandlerTester tester = new HandlerTester() {
Handler h1;
Handler h2;
public void go() {
Broadcaster b = new Broadcaster();
h1 = new H();
h2 = new H();
b.request(MESSAGE_A, h1, MESSAGE_C);
b.request(MESSAGE_A, h2, MESSAGE_D);
b.cancelRequest(MESSAGE_A, h2, MESSAGE_D);
Message msg = new Message();
msg.what = MESSAGE_A;
b.broadcast(msg);
}
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_C && msg.getTarget() == h1) {
success();
} else {
failure();
}
}
};
tester.doTest(1000);
|
|