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.Method; 023import java.util.Collections; 024import java.util.HashSet; 025import java.util.Properties; 026import java.util.Set; 027 028import org.apache.maven.surefire.booter.ProviderParameterNames; 029import org.apache.maven.surefire.util.ScannerFilter; 030 031import ch.powerunit.Test; 032 033/** 034 * @author borettim 035 * 036 */ 037public class PowerUnitProviderScannerFilter implements ScannerFilter { 038 039 private final Set<String> sgroups; 040 041 private final Set<String> sexcludedGroups; 042 043 public PowerUnitProviderScannerFilter(Properties parameters) { 044 String groups = parameters.getProperty( 045 ProviderParameterNames.TESTNG_GROUPS_PROP, ""); 046 String excludedGroups = parameters.getProperty( 047 ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP, ""); 048 Set<String> sgroups = new HashSet<String>(); 049 Set<String> sexcludedGroups = new HashSet<String>(); 050 for (String g : groups.split(",")) { 051 sgroups.add(g); 052 } 053 for (String g : excludedGroups.split(",")) { 054 sexcludedGroups.add(g); 055 } 056 this.sgroups = Collections.unmodifiableSet(sgroups); 057 this.sexcludedGroups = Collections.unmodifiableSet(sexcludedGroups); 058 } 059 060 @Override 061 public boolean accept(@SuppressWarnings("rawtypes") Class testClass) { 062 for (Method m : testClass.getDeclaredMethods()) { 063 if (m.isAnnotationPresent(Test.class)) { 064 return true; 065 } 066 } 067 return false; 068 } 069}