mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-13 16:35:28 +00:00

committed by
Moxie Marlinspike

parent
1323b49c57
commit
cd085faecd
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -16,8 +17,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -26,27 +25,29 @@ import static org.mockito.Matchers.anyFloat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.powermock.api.mockito.PowerMockito.doReturn;
|
||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Log.class, Handler.class, Looper.class, TextUtils.class })
|
||||
@PrepareForTest({ Log.class, Handler.class, Looper.class, TextUtils.class, PreferenceManager.class })
|
||||
public abstract class BaseUnitTest {
|
||||
protected Context context;
|
||||
protected MasterSecret masterSecret;
|
||||
|
||||
protected Context context = mock(Context.class);
|
||||
protected SharedPreferences sharedPreferences = mock(SharedPreferences.class);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = mock(Context.class);
|
||||
masterSecret = new MasterSecret(new SecretKeySpec(new byte[16], "AES"),
|
||||
new SecretKeySpec(new byte[16], "HmacSHA1"));
|
||||
mockStatic(Looper.class);
|
||||
mockStatic(Log.class);
|
||||
mockStatic(Handler.class);
|
||||
mockStatic(TextUtils.class);
|
||||
mockStatic(PreferenceManager.class);
|
||||
|
||||
when(PreferenceManager.getDefaultSharedPreferences(any(Context.class))).thenReturn(sharedPreferences);
|
||||
when(Looper.getMainLooper()).thenReturn(null);
|
||||
PowerMockito.whenNew(Handler.class).withAnyArguments().thenReturn(null);
|
||||
|
||||
@@ -72,12 +73,12 @@ public abstract class BaseUnitTest {
|
||||
}
|
||||
}).when(TextUtils.class, "isEmpty", anyString());
|
||||
|
||||
SharedPreferences mockSharedPreferences = mock(SharedPreferences.class);
|
||||
when(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("");
|
||||
when(mockSharedPreferences.getLong(anyString(), anyLong())).thenReturn(0L);
|
||||
when(mockSharedPreferences.getInt(anyString(), anyInt())).thenReturn(0);
|
||||
when(mockSharedPreferences.getBoolean(anyString(), anyBoolean())).thenReturn(false);
|
||||
when(mockSharedPreferences.getFloat(anyString(), anyFloat())).thenReturn(0f);
|
||||
when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(mockSharedPreferences);
|
||||
when(sharedPreferences.getString(anyString(), anyString())).thenReturn("");
|
||||
when(sharedPreferences.getLong(anyString(), anyLong())).thenReturn(0L);
|
||||
when(sharedPreferences.getInt(anyString(), anyInt())).thenReturn(0);
|
||||
when(sharedPreferences.getBoolean(anyString(), anyBoolean())).thenReturn(false);
|
||||
when(sharedPreferences.getFloat(anyString(), anyFloat())).thenReturn(0f);
|
||||
when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences);
|
||||
when(context.getPackageName()).thenReturn("org.thoughtcrime.securesms");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user