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

net.sf.ipsedixit.integration.junit.IpsedixitDataPopulator Maven / Gradle / Ivy

Go to download

Ipsedixit is a lightweight provider of arbitrary data, mocks and dummies for your Java testing pleasure. It is designed to reduce the amount of boilerplate setup code in your tests, allowing you to spend more time solving more interesting problems. Check out the wiki for the latest docco and examples.

There is a newer version: 1.0.2
Show newest version
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2010, Suncorp Metway Limited. All rights reserved.
//
// This is unpublished proprietary source code of Suncorp Metway Limited.
// The copyright notice above does not evidence any actual or intended
// publication of such source code.
//
////////////////////////////////////////////////////////////////////////////////

package net.sf.ipsedixit.integration.junit;

import net.sf.ipsedixit.DataPopulator;
import net.sf.ipsedixit.DataPopulatorFactory;
import net.sf.ipsedixit.annotation.AnnotationConfiguration;
import net.sf.ipsedixit.integration.Configuration;
import org.junit.rules.TestWatchman;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

/**
 * 

A JUnit Rule that can be used to populate your tests. To use this class, you must be using JUnit 4.8 or better.

*

*

* For example:
* @org.junit.Rule public IpsedixitDataPopulator rule = new IpsedixitDataPopulator(this.getClass()) *

*/ public class IpsedixitDataPopulator extends TestWatchman { private DataPopulator dataPopulator; private Object fixture; /** * Creates a new Rule that will use a {@link net.sf.ipsedixit.annotation.AnnotationConfiguration} to inspect your test * class for annotations, which will be used to configure Ipsedixit. */ public IpsedixitDataPopulator() { } /** * Creates a new Rule that will use the supplied Configuration to populate the class with test data. * * @param configuration the Configuration to use. */ public IpsedixitDataPopulator(Configuration configuration) { dataPopulator = DataPopulatorFactory.INSTANCE.createDefaultDataPopulator(configuration); } @Override public Statement apply(Statement base, FrameworkMethod method, Object target) { fixture = target; if (dataPopulator == null) { AnnotationConfiguration configuration = new AnnotationConfiguration(fixture.getClass()); dataPopulator = DataPopulatorFactory.INSTANCE.createDefaultDataPopulator(configuration); } return super.apply(base, method, target); } @Override public void starting(FrameworkMethod method) { dataPopulator.populate(fixture); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy