Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JUnit TestRule for using in JVM unit tests
package me.vaughandroid.testutils.rules;
import org.joda.time.DateTimeZone;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
* A {@link TestRule} which prevents errors when using the
* <a href="">joda-time-android</a> lib in JVM unit tests.
* Without this rule, tests will log a caught exception:
* {@code Resource not found: "org/joda/time/tz/data/ZoneInfoMap"}
* @author
public class JodaAndroidFixRule implements TestRule {
private final Provider provider;
public JodaAndroidFixRule() {
this(new UTCProvider());
public JodaAndroidFixRule(Provider provider) {
this.provider = provider;
@Override public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override public void evaluate() throws Throwable {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment