@Override @SuppressWarnings("ResourceType") protected void setUp() throws Exception { super.setUp(); preferences = mock(SharedPreferences.class); when(preferences.getBoolean(eq(KEY_PREF_SERVICE_ENABLED), anyBoolean())).thenReturn(true); when(preferences.getBoolean(eq(KEY_PREF_SERVICE_ENABLED), anyBoolean())).thenReturn(true); when(preferences.getString(eq(KEY_PREF_SENDER_ACCOUNT), anyString())) .thenReturn("*****@*****.**"); when(preferences.getString(eq(KEY_PREF_SENDER_PASSWORD), anyString())).thenReturn("password"); when(preferences.getString(eq(KEY_PREF_RECIPIENTS_ADDRESS), anyString())) .thenReturn("*****@*****.**"); when(preferences.getString(eq(KEY_PREF_EMAIL_HOST), anyString())).thenReturn("smtp.mail.com"); when(preferences.getString(eq(KEY_PREF_EMAIL_PORT), anyString())).thenReturn("111"); when(preferences.getStringSet(eq(KEY_PREF_EMAIL_TRIGGERS), anySetOf(String.class))) .thenReturn(DEFAULT_TRIGGERS); when(preferences.getStringSet(eq(KEY_PREF_EMAIL_CONTENT), anySetOf(String.class))) .thenReturn(DEFAULT_CONTENT); networkInfo = mock(NetworkInfo.class); when(networkInfo.isConnected()).thenReturn(true); ConnectivityManager connectivityManager = mock(ConnectivityManager.class); when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); context = mock(Context.class); when(context.getSystemService(eq(Context.CONNECTIVITY_SERVICE))) .thenReturn(connectivityManager); when(context.getContentResolver()).thenReturn(getContext().getContentResolver()); when(context.getResources()).thenReturn(getContext().getResources()); when(context.getSharedPreferences(anyString(), anyInt())).thenReturn(preferences); database = new Database(getContext(), "test.sqlite"); /* not mock context */ database.destroy(); cryptor = mock(Cryptor.class); when(cryptor.decrypt(anyString())) .then( new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return "decrypted " + invocation.getArguments()[0]; } }); transport = mock(MailTransport.class); notifications = mock(Notifications.class); }