Skip to content

Commit 772a273

Browse files
chore(tracing): fix static code warnings
1 parent 1302d0b commit 772a273

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java

+53-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ void tearDown() {
8686
@Test
8787
void shouldCaptureNonHandlerMethod() {
8888
nonHandlerMethod.doSomething();
89-
assertThat(AWSXRay.getTraceEntity().getSubsegments())
89+
90+
assertThat(AWSXRay.getTraceEntity())
91+
.isNotNull();
92+
93+
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
9094
.hasSize(1)
9195
.anySatisfy(segment ->
9296
assertThat(segment.getName()).isEqualTo("## doSomething"));
@@ -95,7 +99,11 @@ void shouldCaptureNonHandlerMethod() {
9599
@Test
96100
void shouldCaptureNonHandlerMethodWithCustomSegmentName() {
97101
nonHandlerMethod.doSomethingCustomName();
98-
assertThat(AWSXRay.getTraceEntity().getSubsegments())
102+
103+
assertThat(AWSXRay.getTraceEntity())
104+
.isNotNull();
105+
106+
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
99107
.hasSize(1)
100108
.anySatisfy(segment ->
101109
assertThat(segment.getName()).isEqualTo("custom"));
@@ -105,6 +113,9 @@ void shouldCaptureNonHandlerMethodWithCustomSegmentName() {
105113
void shouldCaptureTraces() {
106114
requestHandler.handleRequest(new Object(), context);
107115

116+
assertThat(AWSXRay.getTraceEntity())
117+
.isNotNull();
118+
108119
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
109120
.hasSize(1)
110121
.allSatisfy(subsegment -> {
@@ -125,6 +136,9 @@ void shouldCaptureTracesWithExceptionMetaData() {
125136

126137
Throwable exception = catchThrowable(() -> requestHandler.handleRequest(new Object(), context));
127138

139+
assertThat(AWSXRay.getTraceEntity())
140+
.isNotNull();
141+
128142
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
129143
.hasSize(1)
130144
.allSatisfy(subsegment -> {
@@ -147,6 +161,9 @@ void shouldCaptureTracesWithExceptionMetaData() {
147161
void shouldCaptureTracesForStream() throws IOException {
148162
streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
149163

164+
assertThat(AWSXRay.getTraceEntity())
165+
.isNotNull();
166+
150167
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
151168
.hasSize(1)
152169
.allSatisfy(subsegment -> {
@@ -166,6 +183,9 @@ void shouldNotCaptureTracesNotEnabled() throws IOException {
166183
requestHandler = new PowerToolDisabled();
167184
requestHandler.handleRequest(new Object(), context);
168185

186+
assertThat(AWSXRay.getTraceEntity())
187+
.isNotNull();
188+
169189
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
170190
.isEmpty();
171191

@@ -182,6 +202,9 @@ void shouldCaptureTracesWithNoMetadata() {
182202

183203
requestHandler.handleRequest(new Object(), context);
184204

205+
assertThat(AWSXRay.getTraceEntity())
206+
.isNotNull();
207+
185208
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
186209
.hasSize(1)
187210
.allSatisfy(subsegment -> {
@@ -201,6 +224,9 @@ void shouldCaptureTracesForStreamWithNoMetadata() throws IOException {
201224

202225
streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
203226

227+
assertThat(AWSXRay.getTraceEntity())
228+
.isNotNull();
229+
204230
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
205231
.hasSize(1)
206232
.allSatisfy(subsegment -> {
@@ -220,6 +246,9 @@ void shouldCaptureTracesWithNoMetadataDeprecated() {
220246

221247
requestHandler.handleRequest(new Object(), context);
222248

249+
assertThat(AWSXRay.getTraceEntity())
250+
.isNotNull();
251+
223252
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
224253
.hasSize(1)
225254
.allSatisfy(subsegment -> {
@@ -241,6 +270,9 @@ void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
241270

242271
requestHandler.handleRequest(new Object(), context);
243272

273+
assertThat(AWSXRay.getTraceEntity())
274+
.isNotNull();
275+
244276
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
245277
.hasSize(1)
246278
.allSatisfy(subsegment -> {
@@ -263,6 +295,9 @@ void shouldCaptureTracesIfExplicitlyEnabledAndEnvironmentVariableIsDisabled() {
263295

264296
requestHandler.handleRequest(new Object(), context);
265297

298+
assertThat(AWSXRay.getTraceEntity())
299+
.isNotNull();
300+
266301
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
267302
.hasSize(1)
268303
.allSatisfy(subsegment -> {
@@ -284,6 +319,9 @@ void shouldCaptureTracesForSelfReferencingReturnTypesViaCustomMapper() {
284319

285320
requestHandler.handleRequest(new Object(), context);
286321

322+
assertThat(AWSXRay.getTraceEntity())
323+
.isNotNull();
324+
287325
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
288326
.hasSize(1)
289327
.allSatisfy(subsegment -> {
@@ -311,6 +349,9 @@ void shouldCaptureTracesIfExplicitlyEnabledBothAndEnvironmentVariableIsDisabled(
311349

312350
requestHandler.handleRequest(new Object(), context);
313351

352+
assertThat(AWSXRay.getTraceEntity())
353+
.isNotNull();
354+
314355
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
315356
.hasSize(1)
316357
.allSatisfy(subsegment -> {
@@ -333,7 +374,13 @@ void shouldNotCaptureTracesWithExceptionMetaDataIfDisabledViaEnvironmentVariable
333374
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn("false");
334375
requestHandler = new PowerTracerToolEnabledWithException();
335376

336-
catchThrowable(() -> requestHandler.handleRequest(new Object(), context));
377+
Throwable throwable = catchThrowable(() -> requestHandler.handleRequest(new Object(), context));
378+
379+
assertThat(throwable)
380+
.isInstanceOf(RuntimeException.class);
381+
382+
assertThat(AWSXRay.getTraceEntity())
383+
.isNotNull();
337384

338385
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
339386
.hasSize(1)
@@ -358,6 +405,9 @@ void shouldCaptureTracesWithExceptionMetaDataEnabledExplicitlyAndEnvironmentVari
358405

359406
Throwable exception = catchThrowable(() -> requestHandler.handleRequest(new Object(), context));
360407

408+
assertThat(AWSXRay.getTraceEntity())
409+
.isNotNull();
410+
361411
assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
362412
.hasSize(1)
363413
.allSatisfy(subsegment -> {

0 commit comments

Comments
 (0)