001/** 002 * Powerunit - A JDK1.8 test framework 003 * Copyright (C) 2014 Mathieu Boretti. 004 * 005 * This file is part of Powerunit 006 * 007 * Powerunit is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * Powerunit is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package ch.powerunit.surefire; 021 022import java.lang.reflect.Field; 023import java.lang.reflect.Method; 024import java.util.Collections; 025import java.util.HashSet; 026import java.util.Map; 027import java.util.Properties; 028import java.util.Set; 029 030import org.apache.maven.surefire.booter.ProviderParameterNames; 031import org.apache.maven.surefire.util.ScannerFilter; 032 033import ch.powerunit.Test; 034import ch.powerunit.TestDelegate; 035 036/** 037 * @author borettim 038 * 039 */ 040public class PowerUnitProviderScannerFilter implements ScannerFilter { 041 042 private final Set<String> sgroups; 043 044 private final Set<String> sexcludedGroups; 045 046 public PowerUnitProviderScannerFilter(Map<String, String> parameters) { 047 String groups = parameters.getOrDefault(ProviderParameterNames.TESTNG_GROUPS_PROP, ""); 048 String excludedGroups = parameters.getOrDefault(ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP, ""); 049 Set<String> sgroups = new HashSet<String>(); 050 Set<String> sexcludedGroups = new HashSet<String>(); 051 for (String g : groups.split(",")) { 052 sgroups.add(g); 053 } 054 for (String g : excludedGroups.split(",")) { 055 sexcludedGroups.add(g); 056 } 057 this.sgroups = Collections.unmodifiableSet(sgroups); 058 this.sexcludedGroups = Collections.unmodifiableSet(sexcludedGroups); 059 } 060 061 @Override 062 public boolean accept(@SuppressWarnings("rawtypes") Class testClass) { 063 for (Method m : testClass.getDeclaredMethods()) { 064 if (m.isAnnotationPresent(Test.class)) { 065 return true; 066 } 067 } 068 for (Field f : testClass.getDeclaredFields()) { 069 if (f.isAnnotationPresent(TestDelegate.class)) { 070 return true; 071 } 072 } 073 return false; 074 } 075}