Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
created MainEventProcessor
  • Loading branch information
Manoel Aranda Neto committed Oct 23, 2019
commit ccb80f6e298289b533fe24f67d3a24e47b1cf268
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import io.sentry.core.ILogger;
import io.sentry.core.MainEventProcessor;
import io.sentry.core.SentryOptions;

class AndroidOptionsInitializer {
Expand All @@ -17,7 +18,12 @@ static void init(SentryOptions options, Context context, ILogger logger) {
options.setSentryClientName("sentry-android/0.0.1");

ManifestMetadataReader.applyMetadata(context, options);
options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
addProcessors(options, context);
options.setSerializer(new AndroidSerializer(options.getLogger()));
}

private static void addProcessors(SentryOptions options, Context context) {
options.addEventProcessor(new MainEventProcessor(options));
options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.sentry.core.ILogger
import io.sentry.core.SentryOptions
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
Expand All @@ -35,7 +35,7 @@ class AndroidOptionsInitializerTest {
val loggerField = logger.get(sentryOptions)
val innerLogger = loggerField.javaClass.declaredFields.first { it.name == "logger" }
innerLogger.isAccessible = true
assertEquals(AndroidLogger::class, innerLogger.get(loggerField)::class)
assertTrue(innerLogger.get(loggerField) is AndroidLogger)
}

@Test
Expand All @@ -47,7 +47,20 @@ class AndroidOptionsInitializerTest {
val mockLogger = mock<ILogger>()

AndroidOptionsInitializer.init(sentryOptions, mockContext, mockLogger)
val actual = sentryOptions.eventProcessors.firstOrNull { it::class == DefaultAndroidEventProcessor::class }
val actual = sentryOptions.eventProcessors.any { it is DefaultAndroidEventProcessor }
assertNotNull(actual)
}

@Test
fun `MainEventProcessor added to processors list and its the 1st`() {
val sentryOptions = SentryOptions()
val mockContext = mock<Context> {
on { applicationContext } doReturn context
}
val mockLogger = mock<ILogger>()

AndroidOptionsInitializer.init(sentryOptions, mockContext, mockLogger)
val actual = sentryOptions.eventProcessors.firstOrNull { it is DefaultAndroidEventProcessor }
assertNotNull(actual)
}
}
17 changes: 17 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/MainEventProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.sentry.core;

import io.sentry.core.util.Objects;

public class MainEventProcessor implements EventProcessor {

private final SentryOptions options;

public MainEventProcessor(SentryOptions options) {
this.options = Objects.requireNonNull(options, "The SentryOptions is required.");
}

@Override
public SentryEvent process(SentryEvent event) {
return event;
}
}