package com.a.eye.skywalking.api.plugin.assist;

import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
import com.a.eye.skywalking.api.plugin.interceptor.assist.NoConcurrencyAccessObject;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author wusheng
 */
public class NoConcurrencyAccessObjectTest {
    @Test
    public void testEntraExitCounter() {
        NoConcurrencyAccessObject object = new NoConcurrencyAccessObject();
        final EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();
        object.whenEnter(context, new Runnable() {
            @Override
            public void run() {
                context.set("firstEntrance", true);
            }
        });
        object.whenEnter(context, new Runnable() {
            @Override
            public void run() {
                context.set("secondEntrance", true);
            }
        });
        object.whenExist(context, new Runnable() {
            @Override
            public void run() {
                context.set("firstExit", true);
            }
        });
        object.whenExist(context, new Runnable() {
            @Override
            public void run() {
                context.set("lastEntrance", true);
            }
        });

        Assert.assertTrue(!context.isContain("secondEntrance"));
        Assert.assertTrue(!context.isContain("firstExit"));
        Assert.assertTrue(context.isContain("firstEntrance"));
        Assert.assertTrue(context.isContain("lastEntrance"));
    }
}

@@ -219,172 +219,556 @@
 ort 
-org.junit.Assert;%0Aimport org.junit.Test;%0A%0A/**%0A * @author wusheng%0A */%0Apublic class NoConcurrencyAccessObjectTest %7B%0A    @Test%0A    public void testEntraExitCounter() %7B
+com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0A%0A/**%0A * @author wusheng%0A */%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class NoConcurrencyAccessObjectTest %7B%0A%0A    @Mock%0A    private InstanceMethodInvokeContext invokeContext;%0A%0A    @Test%0A    public void testEntraExitCounter() %7B%0A        final EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();
 %0A   
@@ -798,21 +798,20 @@
 sObject 
-objec
+firs
 t = new 
@@ -841,149 +841,205 @@
 ct()
-;%0A        final EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();%0A        object.whenEnter(context, new Runnable() %7B
+%7B%0A%0A            @Override%0A            protected void enter(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) %7B%0A                context.set(%22firstEntrance%22, true);
 %0A   
@@ -1043,33 +1043,26 @@
             
-@Override
+%7D%0A
 %0A           
@@ -1058,39 +1058,53 @@
             
-public
+@Override protected
  void 
-run
+exit
 () %7B%0A       
@@ -1123,39 +1123,35 @@
 text.set(%22firstE
-ntrance
+xit
 %22, true);%0A      
@@ -1163,35 +1163,35 @@
  %7D%0A        %7D
-)
 ;%0A
+%0A
         
 object.whenE
@@ -1182,51 +1182,77 @@
     
-object.whenEnter(context, new Runnable
+NoConcurrencyAccessObject second = new NoConcurrencyAccessObject
 ()
- 
 %7B%0A
+%0A
     
@@ -1278,39 +1278,128 @@
            p
-ublic void run(
+rotected void enter(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext
 ) %7B%0A        
@@ -1461,70 +1461,8 @@
   %7D%0A
-        %7D);%0A        object.whenExist(context, new Runnable() %7B
 %0A   
@@ -1483,36 +1483,28 @@
 ride
-%0A            public
+ protected
  void 
-run
+exit
 () %7B
@@ -1529,33 +1529,36 @@
 ontext.set(%22
-firstExit
+lastEntrance
 %22, true);%0A  
@@ -1578,18 +1578,18 @@
        %7D
-)
 ;
+%0A
 %0A       
@@ -1593,24 +1593,23 @@
     
-objec
+firs
 t.whenE
-xist
+nter
 (con
@@ -1618,153 +1618,140 @@
 xt, 
-new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                context.set(%22lastEntrance%22, true);%0A            %7D%0A        %7D
+invokeContext);%0A        second.whenEnter(context, invokeContext);%0A        first.whenExist(context);%0A        second.whenExist(context
 );%0A%0A

fix issue that test compile failed