Skip to content

Instantly share code, notes, and snippets.

@tskardal
Last active December 17, 2015 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tskardal/5568903 to your computer and use it in GitHub Desktop.
Save tskardal/5568903 to your computer and use it in GitHub Desktop.
Test case to catch GWT serialization errors due to missing empty constructor
package org.example;
import java.util.Set;
import org.junit.Test;
import org.reflections.Reflections;
/*
Entity is something like this --> public interface Entity extends Serializable { }
*/
public class EntityTest {
@Test
public void ensureGWTSerializationRequirementsAreFulfilled() throws Exception {
Reflections reflections = new Reflections("org.example");
Set<Class<? extends Entity>> subTypes = reflections.getSubTypesOf(Entity.class);
for (Class<? extends Entity> c : subTypes) {
try {
c.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
throw new NoSuchMethodException("Class " + c.getName() + " doesn't have an empty constructor");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment