| 514 | } |
| 515 | |
| 516 | @Test |
| 517 | public void testWrapCallable() throws Exception { |
| 518 | Context base = Context.current().withValue(PET, "cat"); |
| 519 | Context current = Context.current().withValue(PET, "fish"); |
| 520 | current.attach(); |
| 521 | |
| 522 | final Object ret = new Object(); |
| 523 | Callable<Object> callable = new Callable<Object>() { |
| 524 | @Override |
| 525 | public Object call() { |
| 526 | runner.run(); |
| 527 | return ret; |
| 528 | } |
| 529 | }; |
| 530 | |
| 531 | assertSame(ret, base.wrap(callable).call()); |
| 532 | assertSame(base, observed); |
| 533 | assertSame(current, Context.current()); |
| 534 | |
| 535 | assertSame(ret, current.wrap(callable).call()); |
| 536 | assertSame(current, observed); |
| 537 | assertSame(current, Context.current()); |
| 538 | |
| 539 | final TestError err = new TestError(); |
| 540 | try { |
| 541 | base.wrap(new Callable<Object>() { |
| 542 | @Override |
| 543 | public Object call() { |
| 544 | throw err; |
| 545 | } |
| 546 | }).call(); |
| 547 | fail("Excepted exception"); |
| 548 | } catch (TestError ex) { |
| 549 | assertSame(err, ex); |
| 550 | } |
| 551 | assertSame(current, Context.current()); |
| 552 | |
| 553 | current.detach(Context.ROOT); |
| 554 | } |
| 555 | |
| 556 | @Test |
| 557 | public void currentContextExecutor() { |