| 483 | } |
| 484 | |
| 485 | @Test |
| 486 | public void testWrapRunnable() { |
| 487 | Context base = Context.current().withValue(PET, "cat"); |
| 488 | Context current = Context.current().withValue(PET, "fish"); |
| 489 | current.attach(); |
| 490 | |
| 491 | base.wrap(runner).run(); |
| 492 | assertSame(base, observed); |
| 493 | assertSame(current, Context.current()); |
| 494 | |
| 495 | current.wrap(runner).run(); |
| 496 | assertSame(current, observed); |
| 497 | assertSame(current, Context.current()); |
| 498 | |
| 499 | final TestError err = new TestError(); |
| 500 | try { |
| 501 | base.wrap(new Runnable() { |
| 502 | @Override |
| 503 | public void run() { |
| 504 | throw err; |
| 505 | } |
| 506 | }).run(); |
| 507 | fail("Expected exception"); |
| 508 | } catch (TestError ex) { |
| 509 | assertSame(err, ex); |
| 510 | } |
| 511 | assertSame(current, Context.current()); |
| 512 | |
| 513 | current.detach(Context.ROOT); |
| 514 | } |
| 515 | |
| 516 | @Test |
| 517 | public void testWrapCallable() throws Exception { |