TestNamedLinkPortalpublic class TestNamedLinkPortal extends com.sun.midp.i3test.TestCase Tests for the LinkPortal class. |
Methods Summary |
---|
public void | runTests()Runs all tests.
declare("testIllegals1");
testIllegals1();
declare("testActual");
testActual();
declare("testIllegals2");
testIllegals2();
| void | testActual()Tests setting and getting of actual data.
Isolate is = Isolate.currentIsolate();
Link sendLink = Link.newLink(is, is);
Link[] links = new Link[3];
links[0] = Link.newLink(is, is);
links[1] = Link.newLink(is, is);
links[2] = Link.newLink(is, is);
LinksReceiver lr = new LinksReceiver(sendLink);
assertFalse("LinksReceiver should be blocked", lr.done);
NamedLinkPortal.putLink("link0", links[0]);
NamedLinkPortal.putLink("link1", links[1]);
NamedLinkPortal.putLink("link2", links[2]);
NamedLinkPortal.sendLinks(sendLink);
Object result = lr.await();
assertTrue("links received without error", result == null);
for (int i = 0; i < 3; i++) {
Link l = NamedLinkPortal.getLink("link" + i);
assertNotSame("link not same", l, links[i]);
assertTrue("links equal", l.equals(links[i]));
}
| void | testIllegals1()Tests passing illegal arguments.
boolean thrown;
Isolate is = Isolate.currentIsolate();
Link sendLink = Link.newLink(is, is);
Link[] links = new Link[3];
links[0] = Link.newLink(is, is);
links[1] = Link.newLink(is, is);
links[2] = Link.newLink(is, is);
thrown = false;
try {
NamedLinkPortal.putLink(null, links[0]);
} catch (IllegalArgumentException iae) {
thrown = true;
}
assertTrue("putting link with null name should throw IAE", thrown);
thrown = false;
try {
NamedLinkPortal.putLink("link1", null);
} catch (IllegalArgumentException iae) {
thrown = true;
}
assertTrue("putting null link should throw IAE", thrown);
thrown = false;
try {
NamedLinkPortal.sendLinks(null);
} catch (IllegalArgumentException iae) {
thrown = true;
}
assertTrue("null send link should throw IAE", thrown);
NamedLinkPortal.putLink("link0", links[0]);
NamedLinkPortal.putLink("link1", links[1]);
NamedLinkPortal.putLink("link2", links[2]);
thrown = false;
try {
Link l = NamedLinkPortal.getLink("link1");
} catch (IllegalStateException ise) {
thrown = true;
}
assertTrue("getting link before links have been received should" +
" throw ISE", thrown);
thrown = false;
links[1].close();
try {
NamedLinkPortal.sendLinks(sendLink);
} catch (IllegalStateException ise) {
thrown = true;
}
assertTrue("trying to send closed link should throw ISE", thrown);
| void | testIllegals2()Tests passing illegal arguments.
boolean thrown;
Isolate is = Isolate.currentIsolate();
Link sendLink = Link.newLink(is, is);
Link l = Link.newLink(is, is);
thrown = false;
try {
NamedLinkPortal.putLink("link", l);
} catch (IllegalStateException iae) {
thrown = true;
}
assertTrue("trying to put link after links have been sent should" +
" throw ISE", thrown);
thrown = false;
try {
NamedLinkPortal.sendLinks(sendLink);
} catch (IllegalStateException iae) {
thrown = true;
}
assertTrue("trying to send links again should throw ISE", thrown);
LinksReceiver lr = new LinksReceiver(sendLink);
Object result = lr.await();
assertTrue("trying to receive links again should produce error",
result != null);
|
|