diff options
author | cyBerta <cyberta@riseup.net> | 2023-05-24 21:48:11 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-07-13 10:53:49 +0200 |
commit | 2caa267277e3d515f84b3d86192c538e17509e44 (patch) | |
tree | 2f6cd7023c61fb0ad6f86daf8722bc7ebb6df787 /app/src | |
parent | af123f7a34eaa7839a238b32f2cb4ef473c9ed22 (diff) |
fix tests after encrypted shared preference usage
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 2 | ||||
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java | 27 |
2 files changed, 19 insertions, 10 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index ee6ccce5..1f5aa74b 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -83,6 +83,8 @@ public class GatewaysManagerTest { putString(CA_CERT, secrets.getString(CA_CERT)). putString(PROVIDER_VPN_CERTIFICATE, secrets.getString(PROVIDER_VPN_CERTIFICATE)) .commit(); + mockStatic(PreferenceHelper.class); + when(PreferenceHelper.getSharedPreferences(any())).thenReturn(sharedPreferences); } diff --git a/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java index 509805d4..d972923c 100644 --- a/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java @@ -16,8 +16,18 @@ */ package se.leap.bitmaskclient.tethering; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; + import android.content.Context; import android.content.IntentFilter; +import android.content.SharedPreferences; import org.junit.Before; import org.junit.Test; @@ -37,19 +47,12 @@ import java.util.Collections; import java.util.Enumeration; import se.leap.bitmaskclient.base.utils.Cmd; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; +import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.testutils.MockSharedPreferences; @RunWith(PowerMockRunner.class) -@PrepareForTest({WifiManagerWrapper.class, TetheringStateManager.class, Cmd.class, NetworkInterface.class}) +@PrepareForTest({WifiManagerWrapper.class, TetheringStateManager.class, Cmd.class, NetworkInterface.class, PreferenceHelper.class}) public class TetheringStateManagerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -64,6 +67,10 @@ public class TetheringStateManagerTest { public void setup() throws Exception { PowerMockito.whenNew(IntentFilter.class).withArguments(anyString()).thenReturn(intentFilter); PowerMockito.whenNew(IntentFilter.class).withNoArguments().thenReturn(intentFilter); + mockStatic(PreferenceHelper.class); + SharedPreferences sharedPreferences = new MockSharedPreferences(); + when(PreferenceHelper.getSharedPreferences(any())).thenReturn(sharedPreferences); + observable = TetheringObservable.getInstance(); } |