From fe3cbeb65b3e4a2e9cfa8154160f541ebc7c3a08 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 7 Jul 2020 17:52:54 +0530 Subject: [PATCH] Mock ContextCompat.getSystemService() using PowerMockito. --- tests/org/kde/kdeconnect/DeviceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/org/kde/kdeconnect/DeviceTest.java b/tests/org/kde/kdeconnect/DeviceTest.java index 69bd9c45..5c5c203d 100644 --- a/tests/org/kde/kdeconnect/DeviceTest.java +++ b/tests/org/kde/kdeconnect/DeviceTest.java @@ -58,7 +58,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Matchers.eq; @RunWith(PowerMockRunner.class) -@PrepareForTest({Base64.class, Log.class, PreferenceManager.class}) +@PrepareForTest({Base64.class, Log.class, PreferenceManager.class, ContextCompat.class}) public class DeviceTest { private Context context; @@ -113,7 +113,8 @@ public class DeviceTest { PowerMockito.when(PreferenceManager.getDefaultSharedPreferences(any())).thenReturn(defaultSettings); RsaHelper.initialiseRsaKeys(context); - Mockito.when(ContextCompat.getSystemService(context, NotificationManager.class)).thenReturn(Mockito.mock(NotificationManager.class)); + PowerMockito.mockStatic(ContextCompat.class); + PowerMockito.when(ContextCompat.getSystemService(context, NotificationManager.class)).thenReturn(Mockito.mock(NotificationManager.class)); } @Test