Package net.java.quickcheck.junit3

Source Code of net.java.quickcheck.junit3.CharacteristicsTestSuiteBuilder

/*
*  Licensed to the author under one or more
*  contributor license agreements.  See the NOTICE file distributed with
*  this work for additional information regarding copyright ownership.
*  The ASF licenses this file to You under the Apache License, Version 2.0
*  (the "License"); you may not use this file except in compliance with
*  the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package net.java.quickcheck.junit3;

import static net.java.quickcheck.junit.support.GeneratorFactory.createGenerator;

import java.lang.reflect.Method;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;
import net.java.quickcheck.generator.support.RoundRobinGenerator;
import net.java.quickcheck.junit.ForAll;
import net.java.quickcheck.junit.support.Discovery;
import net.java.quickcheck.junit.support.GeneratorFactory;

/**
* Create a TestSuite for the given test class. The {@link ForAll} annotation is
* used to add quickcheck specific metadata to test classes. For each the
* annotated method (and generator annotated) a test instance ({@link CharacteristicsTester})
* will be generated.
*/
public class CharacteristicsTestSuiteBuilder {

  public static Test buildSuite(Class<?> testClass) {
    List<Method> characteristicMethods = Discovery
        .getCharacteristicMethods(testClass);
    TestSuite suite = new TestSuite();
    for (Method characteristicMethod : characteristicMethods) {
      addTesters(suite, testClass, characteristicMethod);
    }
    return suite;
  }

  private static void addTesters(TestSuite suite, Class<?> testClass,
      Method characteristicMethod) {

    ForAll annotation = characteristicMethod.getAnnotation(ForAll.class);
    Object testClassInstance = GeneratorFactory.newInstance(testClass);
    suite.addTest(new CharacteristicsTester(testClassInstance,
        new RoundRobinGenerator<Object>(createGenerator(
            testClassInstance, annotation)), characteristicMethod,
        annotation.runs(), annotation.verbose()));
  }

}
TOP

Related Classes of net.java.quickcheck.junit3.CharacteristicsTestSuiteBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.