### Question:
CtEntry extends Entry { @Override public void exit(int count, Object... args) throws ErrorEntryFreeException { trueExit(count, args); } CtEntry(ResourceWrapper resourceWrapper, ProcessorSlot<Object> chain, Context context); @Override void exit(int count, Object... args); @Override void whenTerminate(BiConsumer<Context, Entry> handler); @Override Node getLastNode();  }### Answer:
@Test public void testExitNotMatchCurEntry() { String contextName = "context-rpc"; ContextUtil.enter(contextName); Context context = ContextUtil.getContext(); CtEntry entry1 = null; CtEntry entry2 = null; try { entry1 = new CtEntry(new StringResourceWrapper("res1", EntryType.IN), null, ContextUtil.getContext()); assertSame(entry1, context.getCurEntry()); entry2 = new CtEntry(new StringResourceWrapper("res2", EntryType.IN), null, ContextUtil.getContext()); assertSame(entry2, context.getCurEntry()); entry1.exit(); } catch (ErrorEntryFreeException ex) { assertNotNull(entry1); assertNotNull(entry2); assertNull(entry1.context); assertNull(entry2.context); assertNull(context.getCurEntry()); return; } finally { ContextUtil.exit(); } fail("Mismatch entry-exit should throw an ErrorEntryFreeException"); }
@Test public void testExitLastEntryWithDefaultContext() { final Context defaultContext = getFakeDefaultContext(); ContextUtil.runOnContext(defaultContext, new Runnable() { @Override public void run() { CtEntry entry = new CtEntry(new StringResourceWrapper("res", EntryType.IN), null, ContextUtil.getContext()); assertSame(entry, defaultContext.getCurEntry()); assertSame(defaultContext, ContextUtil.getContext()); entry.exit(); assertNull(defaultContext.getCurEntry()); assertNull(ContextUtil.getContext()); } }); }
@Test public void testExitTwoLastEntriesWithCustomContext() { String contextName = "context-rpc"; ContextUtil.enter(contextName); Context context = ContextUtil.getContext(); try { CtEntry entry1 = new CtEntry(new StringResourceWrapper("resA", EntryType.IN), null, context); entry1.exit(); assertEquals(context, ContextUtil.getContext()); CtEntry entry2 = new CtEntry(new StringResourceWrapper("resB", EntryType.IN), null, context); entry2.exit(); assertEquals(context, ContextUtil.getContext()); } finally { ContextUtil.exit(); assertNull(ContextUtil.getContext()); } }
@Test public void testEntryAndExitWithNullContext() { Context context = new NullContext(); CtEntry entry = new CtEntry(new StringResourceWrapper("testEntryAndExitWithNullContext", EntryType.IN), null, context); assertNull(context.getCurEntry()); entry.exit(); assertNull(context.getCurEntry()); assertEquals(context, entry.context); }