Files
OpenTracks/src/androidTest/java/de/dennisguse/opentracks/TimezoneRule.java
T
Dennis Guse b44bab1ab5 For testing: add rule to mock timezone.
Used by ExportImportTest.csv_export_only()
2022-04-23 15:03:05 +02:00

37 lines
933 B
Java

package de.dennisguse.opentracks;
import androidx.annotation.NonNull;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.util.TimeZone;
public class TimezoneRule implements TestRule {
private final TimeZone mTimeZone;
private TimeZone mDeviceTimeZone;
public TimezoneRule(@NonNull TimeZone timeZone) {
mTimeZone = timeZone;
}
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
mDeviceTimeZone = TimeZone.getDefault();
TimeZone.setDefault(mTimeZone);
base.evaluate();
} finally {
TimeZone.setDefault(mDeviceTimeZone);
}
}
};
}
}