1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.instrumental.agent.junit.extension;
20
21 import static io.earcam.instrumental.agent.junit.AbstractAgentJarTest.AGENT_ARGUMENTS;
22 import static io.earcam.instrumental.agent.junit.extension.DoubleAgentClassTest.SECOND_AGENT_ARGS;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.containsInAnyOrder;
25 import static org.hamcrest.Matchers.instanceOf;
26 import static org.hamcrest.Matchers.is;
27
28 import java.lang.instrument.Instrumentation;
29
30 import org.junit.jupiter.api.AfterAll;
31 import org.junit.jupiter.api.Test;
32
33 import com.acme.SecondStubAgent;
34 import com.acme.StubAgent;
35 import com.acme.StubAgentState;
36
37 @AgentClass(value = SecondStubAgent.class, arguments = SECOND_AGENT_ARGS)
38 @AgentClass(value = StubAgent.class, arguments = AGENT_ARGUMENTS)
39 public class DoubleAgentClassTest {
40
41 public static final String SECOND_AGENT_ARGS = "-Asomething=different";
42
43
44 @AfterAll
45 public static void reset()
46 {
47 StubAgentState.initialize();
48 }
49
50
51 @Test
52 public void test()
53 {
54 assertThat(StubAgentState.agentMainInvocations(), is(2));
55 assertThat(StubAgentState.isPreMainInvoked(), is(false));
56 assertThat(StubAgentState.instrumentation(), is(instanceOf(Instrumentation.class)));
57 assertThat(StubAgentState.arguments(), containsInAnyOrder(AGENT_ARGUMENTS, SECOND_AGENT_ARGS));
58 }
59 }