Skip to content

Commit

Permalink
test non-null configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Mar 8, 2023
1 parent 0caaf30 commit 2bcdf54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package co.elastic.apm.agent.impl;

import co.elastic.apm.agent.MockReporter;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.configuration.ServiceInfo;
import co.elastic.apm.agent.configuration.SpyConfiguration;
Expand All @@ -28,19 +29,19 @@
import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.ElasticContext;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.metrics.Labels;
import co.elastic.apm.agent.objectpool.TestObjectPoolFactory;
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.report.ReporterConfiguration;
import co.elastic.apm.agent.tracer.Outcome;
import co.elastic.apm.agent.tracer.Scope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.stagemonitor.configuration.ConfigurationOptionProvider;
import org.stagemonitor.configuration.ConfigurationRegistry;

import javax.annotation.Nullable;
Expand All @@ -53,6 +54,7 @@
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -698,6 +700,19 @@ void testContextWrapping() {

}

@Test
void testUnknownConfiguration() {
assertThatThrownBy(()-> tracerImpl.getConfig(Object.class))
.isInstanceOf(IllegalStateException.class);

ConfigurationOptionProvider unregisteredConfigProvider = new ConfigurationOptionProvider() {
};

assertThatThrownBy(()-> tracerImpl.getConfig(unregisteredConfigProvider.getClass()))
.isInstanceOf(IllegalStateException.class);

}

private static final class TestContext implements ElasticContext<TestContext> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private SQSMessageAttributesGetter() {
@Nullable
@Override
public String getFirstHeader(String headerName, SQSEvent.SQSMessage carrier) {
if(null != carrier.getMessageAttributes() && carrier.getMessageAttributes().containsKey(headerName)){
if (null != carrier.getMessageAttributes() && carrier.getMessageAttributes().containsKey(headerName)) {
return carrier.getMessageAttributes().get(headerName).getStringValue();
}
return null;
Expand Down

0 comments on commit 2bcdf54

Please sign in to comment.