package org.x2a.cutter;

import com.sun.source.tree.MethodTree;
import org.junit.Assert;
import org.junit.Test;
import org.x2a.cutter.annotation.Cut;
import org.x2a.cutter.cut.JoinPoint;
import org.x2a.cutter.cut.Parameter;
import org.x2a.cutter.cut.PointCut;

import javax.annotation.processing.AbstractProcessor;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

public class TestCut {

    static class TestPC extends PointCut<Boolean> {
        public TestPC(JoinPoint joinPoint, Parameter[] parameters) {
            super(joinPoint, parameters);
        }

        @Override
        public boolean before() {
            return getParameterValue(0).equals("invoke");
        }

        @Override
        public Boolean after(Boolean aBoolean) {
            return true;
        }

        @Override
        public Boolean onSkip() {
            return true;
        }
    }


    @Cut(TestPC.class)
    private boolean methodToCut(String s) {
        return false;
    }


    @Test
    public void testCut() {
        Assert.assertTrue("the cut should've returned true", methodToCut("invoke"));
    }

    @Test
    public void testOnSkip() {
        Assert.assertTrue("onSkip should've been called and should've returned true", methodToCut("no"));
    }

    @Test
    public void testWrappedMethodExists() throws Exception {
        Method method = getClass().getDeclaredMethod("__wrapped__methodToCut", String.class);
        Assert.assertNotNull(method);
        Assert.assertFalse(method.isAccessible());
    }
}

@@ -443,23 +443,22 @@
 ointCut%3C
-Boolean
+String
 %3E %7B%0A    
@@ -733,29 +733,27 @@
 lic 
-Boolean after(Boolean
+String after(String
  aBo
@@ -772,36 +772,39 @@
          return 
-true
+%22after%22
 ;%0A        %7D%0A%0A   
@@ -833,23 +833,22 @@
  public 
-Boolean
+String
  onSkip(
@@ -870,20 +870,25 @@
  return 
-true
+%22skipped%22
 ;%0A      
@@ -934,23 +934,22 @@
 private 
-boolean
+String
  methodT
@@ -984,13 +984,25 @@
 urn 
-false
+%22the real return%22
 ;%0A  
@@ -1066,20 +1066,22 @@
 t.assert
-True
+Equals
 (%22the cu
@@ -1099,32 +1099,41 @@
  returned true%22,
+ %22after%22,
  methodToCut(%22in
@@ -1214,12 +1214,14 @@
 sert
-True
+Equals
 (%22on
@@ -1276,16 +1276,27 @@
 d true%22,
+ %22skipped%22,
  methodT

improve unit tests a bit