Skip to content

Commit fdd52a0

Browse files
committed
Remove mockito from powertools-metrics and re-use TestLamdaContext from powertools-common.
1 parent be3177d commit fdd52a0

File tree

6 files changed

+39
-147
lines changed

6 files changed

+39
-147
lines changed

powertools-common/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,18 @@
155155
<directory>src/main/resources</directory>
156156
</resource>
157157
</resources>
158+
<plugins>
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-jar-plugin</artifactId>
162+
<executions>
163+
<execution>
164+
<goals>
165+
<goal>test-jar</goal>
166+
</goals>
167+
</execution>
168+
</executions>
169+
</plugin>
170+
</plugins>
158171
</build>
159172
</project>

powertools-metrics/pom.xml

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,6 @@
8585
<artifactId>junit-jupiter-engine</artifactId>
8686
<scope>test</scope>
8787
</dependency>
88-
<dependency>
89-
<groupId>org.mockito</groupId>
90-
<artifactId>mockito-core</artifactId>
91-
<scope>test</scope>
92-
</dependency>
93-
<dependency>
94-
<groupId>org.mockito</groupId>
95-
<artifactId>mockito-junit-jupiter</artifactId>
96-
<scope>test</scope>
97-
</dependency>
9888
<dependency>
9989
<groupId>org.slf4j</groupId>
10090
<artifactId>slf4j-simple</artifactId>
@@ -115,6 +105,13 @@
115105
<artifactId>assertj-core</artifactId>
116106
<scope>test</scope>
117107
</dependency>
108+
<dependency>
109+
<groupId>software.amazon.lambda</groupId>
110+
<artifactId>powertools-common</artifactId>
111+
<version>${project.version}</version>
112+
<type>test-jar</type>
113+
<scope>test</scope>
114+
</dependency>
118115
</dependencies>
119116

120117
<profiles>
@@ -137,20 +134,13 @@
137134
</profile>
138135
<profile>
139136
<id>generate-graalvm-files</id>
140-
<dependencies>
141-
<dependency>
142-
<groupId>org.mockito</groupId>
143-
<artifactId>mockito-subclass</artifactId>
144-
<scope>test</scope>
145-
</dependency>
146-
</dependencies>
147137
<build>
148138
<plugins>
149139
<plugin>
150140
<groupId>org.apache.maven.plugins</groupId>
151141
<artifactId>maven-surefire-plugin</artifactId>
152142
<configuration>
153-
<argLine>-Dmockito.mock.maker=subclass -Dorg.graalvm.nativeimage.imagecode=agent
143+
<argLine>-Dorg.graalvm.nativeimage.imagecode=agent
154144
-agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image/software.amazon.lambda/powertools-metrics,experimental-class-define-support
155145
--add-opens java.base/java.util=ALL-UNNAMED
156146
--add-opens java.base/java.lang=ALL-UNNAMED
@@ -162,13 +152,6 @@
162152
</profile>
163153
<profile>
164154
<id>graalvm-native</id>
165-
<dependencies>
166-
<dependency>
167-
<groupId>org.mockito</groupId>
168-
<artifactId>mockito-subclass</artifactId>
169-
<scope>test</scope>
170-
</dependency>
171-
</dependencies>
172155
<build>
173156
<plugins>
174157
<plugin>
@@ -192,38 +175,11 @@
192175
<buildArg>--add-opens java.base/java.lang=ALL-UNNAMED</buildArg>
193176
<buildArg>--no-fallback</buildArg>
194177
<buildArg>-Dorg.graalvm.nativeimage.imagecode=agent</buildArg>
195-
<buildArg>-H:ClassInitialization=net.bytebuddy.ClassFileVersion:rerun</buildArg>
196-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.dispatcher.JavaDispatcher:rerun</buildArg>
197-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.Invoker$Dispatcher:rerun</buildArg>
198-
<buildArg>-H:ClassInitialization=net.bytebuddy.utility.GraalImageCode:rerun</buildArg>
199178
<buildArg>--initialize-at-build-time=org.slf4j.simple.SimpleLogger</buildArg>
200179
<buildArg>--initialize-at-build-time=org.slf4j.LoggerFactory</buildArg>
201180
<buildArg>--initialize-at-build-time=org.junit.Ignore</buildArg>
202181
<buildArg>--initialize-at-build-time=java.lang.annotation.Annotation</buildArg>
203182
<buildArg>--initialize-at-build-time=org.junit.runners.model.FrameworkField</buildArg>
204-
<buildArg>
205-
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase</buildArg>
206-
<buildArg>
207-
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic</buildArg>
208-
<buildArg>
209-
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$1</buildArg>
210-
<buildArg>
211-
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Argument$BindingMechanic$2</buildArg>
212-
<buildArg>
213-
--initialize-at-build-time=net.bytebuddy.utility.dispatcher.JavaDispatcher$DynamicClassLoader</buildArg>
214-
<buildArg>
215-
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable</buildArg>
216-
<buildArg>
217-
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$AbstractBase</buildArg>
218-
<buildArg>
219-
--initialize-at-build-time=net.bytebuddy.description.type.TypeDescription$ForLoadedType</buildArg>
220-
<buildArg>
221-
--initialize-at-build-time=net.bytebuddy.description.method.MethodDescription$ForLoadedMethod</buildArg>
222-
<buildArg>
223-
--initialize-at-build-time=net.bytebuddy.implementation.bind.annotation.Super$Instantiation$2</buildArg>
224-
<buildArg>
225-
--trace-class-initialization=net.bytebuddy.description.type.TypeDescription$ForLoadedType,net.bytebuddy.description.method.MethodDescription$ForLoadedMethod,net.bytebuddy.description.method.MethodDescription$InDefinedShape$AbstractBase$ForLoadedExecutable
226-
</buildArg>
227183
<buildArg>--verbose</buildArg>
228184
</buildArgs>
229185
</configuration>

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/ConfigurationPrecedenceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
3636
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
37-
import software.amazon.lambda.powertools.metrics.testutils.TestContext;
37+
import software.amazon.lambda.powertools.common.stubs.TestLambdaContext;
3838

3939
/**
4040
* Tests to verify the hierarchy of precedence for configuration:
@@ -89,7 +89,7 @@ void annotationShouldOverrideBuilderAndEnvironment() throws Exception {
8989
.build();
9090

9191
RequestHandler<Map<String, Object>, String> handler = new HandlerWithMetricsAnnotation();
92-
Context context = new TestContext();
92+
Context context = new TestLambdaContext();
9393
Map<String, Object> input = new HashMap<>();
9494

9595
// When
@@ -118,7 +118,7 @@ void builderShouldOverrideEnvironment() throws Exception {
118118
.build();
119119

120120
RequestHandler<Map<String, Object>, String> handler = new HandlerWithDefaultMetricsAnnotation();
121-
Context context = new TestContext();
121+
Context context = new TestLambdaContext();
122122
Map<String, Object> input = new HashMap<>();
123123

124124
// When
@@ -141,7 +141,7 @@ void builderShouldOverrideEnvironment() throws Exception {
141141
void environmentVariablesShouldBeUsedWhenNoOverrides() throws Exception {
142142
// Given
143143
RequestHandler<Map<String, Object>, String> handler = new HandlerWithDefaultMetricsAnnotation();
144-
Context context = new TestContext();
144+
Context context = new TestLambdaContext();
145145
Map<String, Object> input = new HashMap<>();
146146

147147
// When
@@ -166,7 +166,7 @@ void shouldUseDefaultsWhenNoConfiguration() throws Exception {
166166
.build();
167167

168168
RequestHandler<Map<String, Object>, String> handler = new HandlerWithDefaultMetricsAnnotation();
169-
Context context = new TestContext();
169+
Context context = new TestLambdaContext();
170170
Map<String, Object> input = new HashMap<>();
171171

172172
// When

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/EmfMetricsLoggerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
4646
import software.amazon.lambda.powertools.metrics.model.MetricResolution;
4747
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
48-
import software.amazon.lambda.powertools.metrics.testutils.TestContext;
48+
import software.amazon.lambda.powertools.common.stubs.TestLambdaContext;
4949

5050
class EmfMetricsLoggerTest {
5151

@@ -373,7 +373,7 @@ void shouldClearDefaultDimensions() throws Exception {
373373
@Test
374374
void shouldCaptureColdStartMetric() throws Exception {
375375
// Given
376-
Context testContext = new TestContext();
376+
Context testContext = new TestLambdaContext();
377377

378378
// When
379379
metrics.captureColdStartMetric(testContext);
@@ -425,7 +425,7 @@ void shouldReuseNamespaceForColdStartMetric() throws Exception {
425425
String customNamespace = "CustomNamespace";
426426
metrics.setNamespace(customNamespace);
427427

428-
Context testContext = new TestContext();
428+
Context testContext = new TestLambdaContext();
429429

430430
DimensionSet dimensions = DimensionSet.of("CustomDim", "CustomValue");
431431

@@ -497,7 +497,7 @@ void shouldNotFlushMetricsWhenDisabled() {
497497
@SetEnvironmentVariable(key = "POWERTOOLS_METRICS_DISABLED", value = "true")
498498
void shouldNotCaptureColdStartMetricWhenDisabled() {
499499
// Given
500-
Context testContext = new TestContext();
500+
Context testContext = new TestLambdaContext();
501501

502502
// When
503503
metrics.captureColdStartMetric(testContext);

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspectTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import software.amazon.lambda.powertools.metrics.Metrics;
3838
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3939
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
40-
import software.amazon.lambda.powertools.metrics.testutils.TestContext;
40+
import software.amazon.lambda.powertools.common.stubs.TestLambdaContext;
4141

4242
class LambdaMetricsAspectTest {
4343

@@ -74,7 +74,7 @@ void tearDown() throws Exception {
7474
void shouldCaptureMetricsFromAnnotatedHandler() throws Exception {
7575
// Given
7676
RequestHandler<Map<String, Object>, String> handler = new HandlerWithMetricsAnnotation();
77-
Context context = new TestContext();
77+
Context context = new TestLambdaContext();
7878
Map<String, Object> input = new HashMap<>();
7979

8080
// When
@@ -98,7 +98,7 @@ void shouldCaptureMetricsFromAnnotatedHandler() throws Exception {
9898
void shouldOverrideEnvironmentVariablesWithAnnotation() throws Exception {
9999
// Given
100100
RequestHandler<Map<String, Object>, String> handler = new HandlerWithMetricsAnnotation();
101-
Context context = new TestContext();
101+
Context context = new TestLambdaContext();
102102
Map<String, Object> input = new HashMap<>();
103103

104104
// When
@@ -120,7 +120,7 @@ void shouldOverrideEnvironmentVariablesWithAnnotation() throws Exception {
120120
void shouldUseEnvironmentVariablesWhenNoAnnotationOverrides() throws Exception {
121121
// Given
122122
RequestHandler<Map<String, Object>, String> handler = new HandlerWithDefaultMetricsAnnotation();
123-
Context context = new TestContext();
123+
Context context = new TestLambdaContext();
124124
Map<String, Object> input = new HashMap<>();
125125

126126
// When
@@ -140,7 +140,7 @@ void shouldUseEnvironmentVariablesWhenNoAnnotationOverrides() throws Exception {
140140
void shouldCaptureColdStartMetricWhenConfigured() throws Exception {
141141
// Given
142142
RequestHandler<Map<String, Object>, String> handler = new HandlerWithColdStartMetricsAnnotation();
143-
Context context = new TestContext();
143+
Context context = new TestLambdaContext();
144144
Map<String, Object> input = new HashMap<>();
145145

146146
// When
@@ -166,7 +166,7 @@ void shouldCaptureColdStartMetricWhenConfigured() throws Exception {
166166
void shouldNotIncludeServiceDimensionInColdStartMetricWhenServiceUndefined() throws Exception {
167167
// Given - no service name set, so it will use the default undefined value
168168
RequestHandler<Map<String, Object>, String> handler = new HandlerWithColdStartMetricsAnnotation();
169-
Context context = new TestContext();
169+
Context context = new TestLambdaContext();
170170
Map<String, Object> input = new HashMap<>();
171171

172172
// When
@@ -195,7 +195,7 @@ void shouldNotIncludeServiceDimensionInColdStartMetricWhenServiceUndefined() thr
195195
void shouldUseCustomFunctionNameWhenProvidedForColdStartMetric() throws Exception {
196196
// Given
197197
RequestHandler<Map<String, Object>, String> handler = new HandlerWithCustomFunctionName();
198-
Context context = new TestContext();
198+
Context context = new TestLambdaContext();
199199
Map<String, Object> input = new HashMap<>();
200200

201201
// When
@@ -228,7 +228,7 @@ void shouldUseCustomFunctionNameWhenProvidedForColdStartMetric() throws Exceptio
228228
void shouldUseServiceNameWhenProvidedForColdStartMetric() throws Exception {
229229
// Given
230230
RequestHandler<Map<String, Object>, String> handler = new HandlerWithServiceNameAndColdStart();
231-
Context context = new TestContext();
231+
Context context = new TestLambdaContext();
232232
Map<String, Object> input = new HashMap<>();
233233

234234
// When
@@ -247,7 +247,7 @@ void shouldUseServiceNameWhenProvidedForColdStartMetric() throws Exception {
247247
void shouldHaveNoEffectOnNonHandlerMethod() {
248248
// Given
249249
RequestHandler<Map<String, Object>, String> handler = new HandlerWithAnnotationOnWrongMethod();
250-
Context context = new TestContext();
250+
Context context = new TestLambdaContext();
251251
Map<String, Object> input = new HashMap<>();
252252

253253
// When

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/testutils/TestContext.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)