All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sft.FixturesHolder Maven / Gradle / Ivy

There is a newer version: 1.9
Show newest version
/*******************************************************************************
 * 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
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy