Created
March 16, 2012 14:44
-
-
Save mgenov/2050379 to your computer and use it in GitHub Desktop.
PolymorphicTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Person { | |
@Id | |
private Long id; | |
@Embedded(polymorphic = true) | |
private State state; | |
} | |
static class State { | |
private String value; | |
@SuppressWarnings("unused") | |
State() { | |
} | |
public State(String value) { | |
this.value = value; | |
} | |
} | |
static class Active extends State { | |
public Active() { | |
super("Active"); | |
} | |
} | |
static class Terminated extends State { | |
public Terminated() { | |
super("Terminated"); | |
} | |
} | |
@Test | |
public void usingPolymorphicEmbeddedObject() { | |
Person person = new Person(); | |
person.state = new Terminated(); | |
ObjectDatastore datastore = new AnnotationObjectDatastore(); | |
datastore.store().instance(person).now(); | |
datastore.disassociateAll(); | |
person = datastore.load().type(Person.class).id(person.id).now(); | |
assertThat(person.state,is(instanceOf(Terminated.class))); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment