| 9 | import java.util.concurrent.Callable; |
| 10 | |
| 11 | public class DynamicWind { |
| 12 | private int before; |
| 13 | private int task; |
| 14 | private int after; |
| 15 | private int continuationCount; |
| 16 | private Callback<Integer> continuationReference; |
| 17 | |
| 18 | private static void expect(boolean v) { |
| 19 | if (! v) throw new RuntimeException(); |
| 20 | } |
| 21 | |
| 22 | private void unwindTest(final Callable<Integer> unwind) throws Exception { |
| 23 | System.out.println("unwindTest enter"); |
| 24 | |
| 25 | try { |
| 26 | expect(dynamicWind(new Runnable() { |
| 27 | public void run() { |
| 28 | System.out.println("unwindTest before"); |
| 29 | |
| 30 | expect(before == 0); |
| 31 | expect(task == 0); |
| 32 | expect(after == 0); |
| 33 | |
| 34 | before = 1; |
| 35 | } |
| 36 | }, new Callable<Integer>() { |
| 37 | public Integer call() throws Exception { |
| 38 | System.out.println("unwindTest thunk"); |
| 39 | |
| 40 | expect(before == 1); |
| 41 | expect(task == 0); |
| 42 | expect(after == 0); |
| 43 | |
| 44 | task = 1; |
| 45 | |
| 46 | return unwind.call(); |
| 47 | } |
| 48 | }, |
| 49 | new Runnable() { |
| 50 | public void run() { |
| 51 | System.out.println("unwindTest after"); |
| 52 | |
| 53 | expect(before == 1); |
| 54 | expect(task == 1); |
| 55 | expect(after == 0); |
| 56 | |
| 57 | after = 1; |
| 58 | } |
| 59 | }) == 42); |
| 60 | } catch (MyException e) { |
| 61 | e.printStackTrace(); |
| 62 | } |
| 63 | |
| 64 | System.out.println("unwindTest expect"); |
| 65 | |
| 66 | expect(before == 1); |
| 67 | expect(task == 1); |
| 68 | expect(after == 1); |
nothing calls this directly
no outgoing calls
no test coverage detected