com.googlecode.objectify.test.RegisterTests Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore
The newest version!
package com.googlecode.objectify.test;
import javax.persistence.Embedded;
import javax.persistence.Id;
import org.testng.annotations.Test;
import com.googlecode.objectify.annotation.Cached;
/**
* Basic tests for registering entities
*
* @author Matt Quail http://madbean.com/
*/
public class RegisterTests extends TestBase
{
@Cached
public static class NonPublicConstructor
{
@Id
Long id;
private NonPublicConstructor() { }
}
@Cached
public static class NoNoargConstructors
{
@Id
Long id;
public NoNoargConstructors(long id)
{
this.id = id;
}
}
public static class BadStruct {
int age;
public BadStruct(int age) {
this.age = age;
}
}
@Cached
public static class HasEmbedded {
@Id
Long id;
@Embedded
BadStruct name;
}
@Test
public void testNoArgConstructor()
{
assertRegisterSucceeds(NonPublicConstructor.class);
assertRegisterFails(NoNoargConstructors.class, IllegalStateException.class);
assertRegisterFails(HasEmbedded.class, IllegalStateException.class);
}
private void assertRegisterSucceeds(Class entity)
{
try
{
this.fact.register(entity);
}
catch (Exception e)
{
assert false : "Unexpected exception of type " + e.getClass();
}
}
private void assertRegisterFails(Class entity, Class expectedException)
{
try
{
this.fact.register(entity);
assert false : "Shouldn't be register " + entity.getName();
}
catch (Exception e)
{
assert expectedException.isInstance(e) : "Unexpected exception of type " + e.getClass();
}
}
}