T
- The type of the object to build.public abstract class AbstractTestdataBuilder<T> extends Object implements TestdataBuilder<T>
TestdataBuilder
.
Implementation example: public class PersonTestDataBuilder extends AbstractTestdataBuilder{ ... public PersonTestDataBuilder() { super(); } public PersonTestDataBuilder(EntityManager entityManager) { super(entityManager); } public PersonTestDataBuilder withName(String name){ this.withName = name; return this; } public PersonTestDataBuilder withAddress(Address address){ this.withName = name; return this; } public Person build() { Person person = new Person(); ... return person; } Usage example: Person transientPerson = new PersonTestDataBuilder(em).build(); Person persistedPerson = new PersonTestDataBuilder(em).buildAndSave(); new PersonTestDataBuilder(em).withAddress(address).buildAndSave();
Constructor and Description |
---|
AbstractTestdataBuilder()
Creates a new
TestdataBuilder without persistence. |
AbstractTestdataBuilder(javax.persistence.EntityManager entityManager)
Creates a new
TestdataBuilder with persistence. |
Modifier and Type | Method and Description |
---|---|
T |
buildAndSave()
Creates a new instance of generic type and saves the instance.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
build
public AbstractTestdataBuilder(javax.persistence.EntityManager entityManager)
TestdataBuilder
with persistence.entityManager
- EntityManager
to be used by this
TestdataBuilder
public AbstractTestdataBuilder()
TestdataBuilder
without persistence.public final T buildAndSave()
buildAndSave
in interface TestdataBuilder<T>
IllegalStateException
- if the TestdataBuilder
is constructed without an
EntityManager
Copyright © 2014. All rights reserved.