001package org.w3.ldp.testsuite.transformer; 002 003import java.lang.reflect.Constructor; 004import java.lang.reflect.Method; 005import java.util.HashMap; 006import java.util.Map; 007 008import org.testng.IAnnotationTransformer; 009import org.testng.annotations.ITestAnnotation; 010 011public class MethodEnabler implements IAnnotationTransformer { 012 013 private static Map<String, Boolean> transforms = new HashMap<>(); 014 private static boolean defEnabled = true; 015 016 public synchronized static void includeMethod(String name) { 017 transforms.put(name, true); 018 } 019 020 public static void excludeMethod(String name) { 021 transforms.put(name, false); 022 } 023 024 public static void setDefault(boolean enabled) { 025 defEnabled = enabled; 026 } 027 028 @SuppressWarnings("rawtypes") 029 @Override 030 public void transform(ITestAnnotation annotation, Class testClass, 031 Constructor testConstructor, Method testMethod) { 032 String methodName = testMethod.getName(); 033 034 if (transforms.containsKey(methodName)) { 035 annotation.setEnabled(transforms.get(methodName)); 036 037 String[] dependencies = annotation.getDependsOnMethods(); 038 for (String dep : dependencies) { 039 transforms.put(dep, true); 040 } 041 } else { 042 // If it is not in the transforms map and defEnabled is true, 043 // do what its annotation says 044 annotation.setEnabled(annotation.getEnabled() && defEnabled); 045 } 046 } 047}