Skip to content

Commit

Permalink
Merge pull request #2190 from newrelic/mockito_test_branch
Browse files Browse the repository at this point in the history
Mockito test branch
  • Loading branch information
jbedell-newrelic authored Jan 3, 2025
2 parents fafe3de + 3f9efec commit 0704419
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import com.newrelic.agent.tracers.servlet.MockHttpRequest;
import com.newrelic.agent.tracers.servlet.MockHttpResponse;
import com.newrelic.api.agent.NewRelicApiImplementation;
import com.newrelic.test.marker.RequiresFork;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -33,6 +35,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

@Category(RequiresFork.class)
public class AgentAttributeSenderTest {

private static final String APP_NAME = "NAME";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
import com.newrelic.agent.threads.ThreadNames;
import com.newrelic.agent.tracers.ClassMethodSignature;
import com.newrelic.agent.tracers.Tracer;
import com.newrelic.test.marker.RequiresFork;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashSet;

@Category(RequiresFork.class)
public class TransactionProfileTest {

TransactionProfile target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.stats.StatsService;
import com.newrelic.agent.tracing.DistributedTraceServiceImpl;
import com.newrelic.test.marker.RequiresFork;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

import java.io.ByteArrayInputStream;
Expand All @@ -51,6 +53,7 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;

@Category(RequiresFork.class)
public class InsightsServiceImplTest {

private static final String appName = "Dude";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import com.newrelic.agent.config.AgentConfigImpl;
import com.newrelic.agent.config.TransactionTracerConfigImpl;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.test.marker.RequiresFork;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

@Category(RequiresFork.class) // Token Timeout is stored as a static and will not get the new value from the test if this is not forked
public class AsyncTransactionServiceTest {

@Test(timeout = 90000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
import com.newrelic.agent.tracers.Tracer;
import com.newrelic.agent.tracers.servlet.MockHttpRequest;
import com.newrelic.agent.tracers.servlet.MockHttpResponse;
import com.newrelic.test.marker.RequiresFork;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mockito;
Expand All @@ -54,6 +56,7 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;

@Category(RequiresFork.class)
@RunWith(Parameterized.class)
public class W3CTraceContextCrossAgentTest {
private MockServiceManager serviceManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
import com.newrelic.agent.tracers.servlet.BasicRequestRootTracer;
import com.newrelic.agent.tracers.servlet.MockHttpRequest;
import com.newrelic.agent.tracers.servlet.MockHttpResponse;
import com.newrelic.test.marker.RequiresFork;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.objectweb.asm.Opcodes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Category(RequiresFork.class)
public class AsyncTransactionTest implements TransactionListener {

private TransactionData data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,15 @@ private void assertMetricWasRecorded(String expectedMetricName) {
break;
}
String methodName = invocation.getMethod().getName();
Object rawArgument = invocation.getRawArguments()[0];
if (rawArgument instanceof IncrementCounter) {
String metricName = invocation.<IncrementCounter>getArgument(0).getName();
found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
} else if (rawArgument instanceof RecordDataUsageMetric) {
String metricName = invocation.<RecordDataUsageMetric>getArgument(0).getName();
found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
if (invocation.getRawArguments() != null && invocation.getRawArguments().length > 0) {
Object rawArgument = invocation.getRawArguments()[0];
if (rawArgument instanceof IncrementCounter) {
String metricName = invocation.<IncrementCounter>getArgument(0).getName();
found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
} else if (rawArgument instanceof RecordDataUsageMetric) {
String metricName = invocation.<RecordDataUsageMetric>getArgument(0).getName();
found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
}
}
}
assertTrue("Could not find metric: " + expectedMetricName, found);
Expand Down

0 comments on commit 0704419

Please sign in to comment.