summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-01-25 23:20:35 +0100
committercyBerta <cyberta@riseup.net>2024-01-25 23:20:35 +0100
commit2bcbfb1d537fe8f616adc252fac7c3e8673ebaa7 (patch)
tree6858b41f6e6aab41e80212c71ae4ffe8e1aacc11 /app/src
parent8b3a140602108f66d5183623a7788dc35c121e59 (diff)
improve TimezoneHelper, don't allow to set the TimezoneInterface outside of UnitTests
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/TimezoneHelper.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/TimezoneHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/TimezoneHelper.java
index c543368d..63b12fd3 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/TimezoneHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/TimezoneHelper.java
@@ -4,6 +4,8 @@ import androidx.annotation.VisibleForTesting;
import java.util.Calendar;
+import de.blinkt.openvpn.core.NativeUtils;
+
public class TimezoneHelper {
public interface TimezoneInterface {
@@ -14,6 +16,9 @@ public class TimezoneHelper {
@VisibleForTesting
public TimezoneHelper(TimezoneInterface timezoneInterface) {
+ if (!NativeUtils.isUnitTest()) {
+ throw new IllegalStateException("TimezoneHelper injected with timezoneInterface outside of an unit test");
+ }
instance = timezoneInterface;
}
@@ -33,7 +38,7 @@ public class TimezoneHelper {
return get().getCurrentTimezone();
}
- public static class DefaultTimezoneHelper implements TimezoneInterface {
+ private static class DefaultTimezoneHelper implements TimezoneInterface {
@Override
public int getCurrentTimezone() {
return Calendar.getInstance().get(Calendar.ZONE_OFFSET) / 3600000;