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

com.tngtech.jgiven.config.ConfigurationUtil Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package com.tngtech.jgiven.config;

import java.util.concurrent.ExecutionException;

import com.google.common.base.Throwables;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.tngtech.jgiven.annotation.JGivenConfiguration;
import com.tngtech.jgiven.impl.util.ReflectionUtil;

public class ConfigurationUtil {

    private static final LoadingCache, AbstractJGivenConfiguration> configurations = CacheBuilder.newBuilder().build(
        new CacheLoader, AbstractJGivenConfiguration>() {
            @Override
            public AbstractJGivenConfiguration load( Class key ) throws Exception {
                AbstractJGivenConfiguration result = (AbstractJGivenConfiguration) ReflectionUtil.newInstance( key );
                result.configure();
                return result;
            }
        } );

    public static AbstractJGivenConfiguration getConfiguration( Class testClass ) {
        JGivenConfiguration annotation = testClass.getAnnotation( JGivenConfiguration.class );
        Class configuration;
        if( annotation == null ) {
            configuration = DefaultConfiguration.class;
        } else {
            configuration = annotation.value();
        }

        try {
            return configurations.get( configuration );
        } catch( ExecutionException e ) {
            throw Throwables.propagate( e.getCause() );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy