sft.FixturesHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SimpleFunctionalTest Show documentation
Show all versions of SimpleFunctionalTest Show documentation
A JUnit extension to easily adopt functional testing and acceptance testing
/*******************************************************************************
* Copyright (c) 2013, 2014 Sylvain Lézier.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sylvain Lézier - initial implementation
*******************************************************************************/
package sft;
import java.lang.reflect.Method;
import java.util.ArrayList;
import static java.lang.reflect.Modifier.isPrivate;
import static java.lang.reflect.Modifier.isProtected;
public class FixturesHolder {
public final Object object;
public final Class> classUnderTest;
public final ArrayList fixtures;
public FixturesHolder(Object object,FixturesVisibility fixturesVisibility,DefaultConfiguration configuration) throws Exception {
this.object = object;
classUnderTest = object.getClass();
fixtures = extractFixtures(fixturesVisibility,configuration);
}
protected ArrayList extractFixtures(FixturesVisibility fixturesVisibility,DefaultConfiguration configuration) throws Exception {
ArrayList fixtures = new ArrayList();
for (Method method : getSupportMethod(fixturesVisibility)) {
fixtures.add(new Fixture(method,configuration));
}
return fixtures;
}
private ArrayList getSupportMethod(FixturesVisibility fixturesVisibility) {
ArrayList testMethods = new ArrayList();
for (Method method : classUnderTest.getDeclaredMethods()) {
if( fixturesVisibility == FixturesVisibility.All ){
testMethods.add(method);
}else if (isPrivate(method.getModifiers()) || isProtected(method.getModifiers())) {
testMethods.add(method);
}
}
return testMethods;
}
enum FixturesVisibility{
All,PrivateOrProtectedOnly
}
}