From 7dd2cbdb375bb895790e638a483dc6a9d5b694aa Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 12 Dec 2024 18:46:04 +0100 Subject: [PATCH] need this for tests --- .../SentryNativeAndroidTests.cs | 9 ++++----- .../TestJniExecutor.cs | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/Sentry.Unity.Android.Tests/TestJniExecutor.cs diff --git a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs index 08ed14f9e..3067c6eb1 100644 --- a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs +++ b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs @@ -13,7 +13,7 @@ public class SentryNativeAndroidTests private Action _fakeReinstallSentryNativeBackendStrategy; private TestUnityInfo _sentryUnityInfo = null!; private TestSentryJava _testSentryJava = null!; - private TestLogger _logger = new(); + private TestLogger _logger = null!; private SentryUnityOptions _options = null!; public SentryNativeAndroidTests() @@ -28,10 +28,11 @@ public void SetUp() _reinstallCalled = false; _sentryUnityInfo = new TestUnityInfo { IL2CPP = false }; - SentryNativeAndroid.JniExecutor ??= new JniExecutor(_logger); + SentryNativeAndroid.JniExecutor = new TestJniExecutor(); _testSentryJava = new TestSentryJava(); SentryNativeAndroid.SentryJava = _testSentryJava; + _logger = new TestLogger(); _options = new SentryUnityOptions { Debug = true, @@ -41,12 +42,10 @@ public void SetUp() } [TearDown] - public void TearDown() - { + public void TearDown() => _fakeReinstallSentryNativeBackendStrategy = Interlocked.Exchange(ref SentryNative.ReinstallSentryNativeBackendStrategy!, _originalReinstallSentryNativeBackendStrategy)!; - } [Test] public void Configure_DefaultConfiguration_SetsScopeObserver() diff --git a/test/Sentry.Unity.Android.Tests/TestJniExecutor.cs b/test/Sentry.Unity.Android.Tests/TestJniExecutor.cs new file mode 100644 index 000000000..7341d1509 --- /dev/null +++ b/test/Sentry.Unity.Android.Tests/TestJniExecutor.cs @@ -0,0 +1,20 @@ +using System; + +namespace Sentry.Unity.Android.Tests; + +public class TestJniExecutor : IJniExecutor +{ + public TResult? Run(Func jniOperation, TimeSpan? timeout = null) + { + return default; + } + + public void Run(Action jniOperation, TimeSpan? timeout = null) + { + } + + public void Dispose() + { + // TODO release managed resources here + } +}