|
| 1 | +package com.instabug.flutter; |
| 2 | + |
| 3 | +import static org.mockito.ArgumentMatchers.any; |
| 4 | +import static org.mockito.ArgumentMatchers.eq; |
| 5 | +import static org.mockito.Mockito.mock; |
| 6 | +import static org.mockito.Mockito.mockStatic; |
| 7 | + |
| 8 | +import com.instabug.flutter.generated.SessionReplayPigeon; |
| 9 | +import com.instabug.flutter.modules.SessionReplayApi; |
| 10 | +import com.instabug.flutter.util.GlobalMocks; |
| 11 | +import com.instabug.library.sessionreplay.SessionReplay; |
| 12 | + |
| 13 | +import org.junit.After; |
| 14 | +import org.junit.Before; |
| 15 | +import org.junit.Test; |
| 16 | +import org.mockito.MockedStatic; |
| 17 | + |
| 18 | +import io.flutter.plugin.common.BinaryMessenger; |
| 19 | + |
| 20 | + |
| 21 | +public class SessionReplayApiTest { |
| 22 | + private final SessionReplayApi api = new SessionReplayApi(); |
| 23 | + private MockedStatic<SessionReplay> mSessionReplay; |
| 24 | + private MockedStatic<SessionReplayPigeon.SessionReplayHostApi> mHostApi; |
| 25 | + |
| 26 | + @Before |
| 27 | + public void setUp() throws NoSuchMethodException { |
| 28 | + mSessionReplay = mockStatic(SessionReplay.class); |
| 29 | + mHostApi = mockStatic(SessionReplayPigeon.SessionReplayHostApi.class); |
| 30 | + GlobalMocks.setUp(); |
| 31 | + } |
| 32 | + |
| 33 | + @After |
| 34 | + public void cleanUp() { |
| 35 | + mSessionReplay.close(); |
| 36 | + mHostApi.close(); |
| 37 | + GlobalMocks.close(); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testInit() { |
| 42 | + BinaryMessenger messenger = mock(BinaryMessenger.class); |
| 43 | + |
| 44 | + SessionReplayApi.init(messenger); |
| 45 | + |
| 46 | + mHostApi.verify(() -> SessionReplayPigeon.SessionReplayHostApi.setup(eq(messenger), any(SessionReplayApi.class))); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testSetEnabled() { |
| 51 | + boolean isEnabled = true; |
| 52 | + |
| 53 | + api.setEnabled(isEnabled); |
| 54 | + |
| 55 | + mSessionReplay.verify(() -> SessionReplay.setEnabled(true)); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testSetNetworkLogsEnabled() { |
| 60 | + boolean isEnabled = true; |
| 61 | + |
| 62 | + api.setNetworkLogsEnabled(isEnabled); |
| 63 | + |
| 64 | + mSessionReplay.verify(() -> SessionReplay.setNetworkLogsEnabled(true)); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testSetInstabugLogsEnabled() { |
| 69 | + boolean isEnabled = true; |
| 70 | + |
| 71 | + api.setInstabugLogsEnabled(isEnabled); |
| 72 | + |
| 73 | + mSessionReplay.verify(() -> SessionReplay.setIBGLogsEnabled(true)); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void testSetUserStepsEnabled() { |
| 78 | + boolean isEnabled = true; |
| 79 | + |
| 80 | + api.setUserStepsEnabled(isEnabled); |
| 81 | + |
| 82 | + mSessionReplay.verify(() -> SessionReplay.setUserStepsEnabled(true)); |
| 83 | + } |
| 84 | + |
| 85 | +} |
| 86 | + |
0 commit comments