1 package test.annotationtransformer; 2 3 import org.testng.IAnnotationTransformer; 4 import org.testng.annotations.ITestAnnotation; 5 6 import java.lang.reflect.Constructor; 7 import java.lang.reflect.Method; 8 9 public class MyParamTransformer implements IAnnotationTransformer { 10 11 private boolean success = true; 12 13 @Override transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod)14 public void transform(ITestAnnotation annotation, Class testClass, 15 Constructor testConstructor, Method testMethod) { 16 if (!onlyOneNonNull(testClass, testConstructor, testMethod)) { 17 success = false; 18 } 19 } 20 onlyOneNonNull(Class testClass, Constructor testConstructor, Method testMethod)21 public static boolean onlyOneNonNull(Class testClass, Constructor testConstructor, Method testMethod) { 22 return ((testClass != null && testConstructor == null && testMethod == null) || 23 (testClass == null && testConstructor != null && testMethod == null) || 24 (testClass == null && testConstructor == null && testMethod != null) ); 25 } 26 isSuccess()27 public boolean isSuccess() { 28 return success; 29 } 30 } 31