16
16
17
17
import static org .assertj .core .api .Assertions .assertThat ;
18
18
import static org .assertj .core .api .Assertions .entry ;
19
- import static org .mockito .Mockito .mock ;
20
- import static org .mockito .Mockito .verify ;
21
19
import static software .amazon .lambda .powertools .tracing .TracingUtils .withEntitySubsegment ;
22
20
23
- import com .amazonaws .services .lambda .runtime .Context ;
24
- import com .amazonaws .xray .AWSXRay ;
25
- import com .amazonaws .xray .entities .Entity ;
26
21
import org .junit .jupiter .api .AfterEach ;
27
22
import org .junit .jupiter .api .BeforeEach ;
28
23
import org .junit .jupiter .api .Test ;
29
24
25
+ import com .amazonaws .xray .AWSXRay ;
26
+ import com .amazonaws .xray .entities .Entity ;
27
+
30
28
class TracingUtilsTest {
31
29
@ BeforeEach
32
30
void setUp () {
@@ -55,8 +53,7 @@ void shouldSetAnnotationOnCurrentSubSegment() {
55
53
.contains (
56
54
entry ("stringKey" , "val" ),
57
55
entry ("numberKey" , 10 ),
58
- entry ("booleanKey" , false )
59
- );
56
+ entry ("booleanKey" , false ));
60
57
}
61
58
62
59
@ Test
@@ -76,10 +73,8 @@ void shouldSetMetadataOnCurrentSubSegment() {
76
73
assertThat (AWSXRay .getTraceEntity ().getMetadata ())
77
74
.hasSize (1 )
78
75
.containsKey ("service_undefined" )
79
- .satisfies (map ->
80
- assertThat (map .get ("service_undefined" ))
81
- .containsEntry ("key" , "val" )
82
- );
76
+ .satisfies (map -> assertThat (map .get ("service_undefined" ))
77
+ .containsEntry ("key" , "val" ));
83
78
}
84
79
85
80
@ Test
@@ -92,21 +87,14 @@ void shouldNotSetMetaDataIfNoCurrentSubSegment() {
92
87
93
88
@ Test
94
89
void shouldInvokeCodeBlockWrappedWithinSubsegment () {
95
- Context test = mock (Context .class );
96
-
97
- TracingUtils .withSubsegment ("testSubSegment" , subsegment ->
98
- {
90
+ TracingUtils .withSubsegment ("testSubSegment" , subsegment -> {
99
91
subsegment .putAnnotation ("key" , "val" );
100
92
subsegment .putMetadata ("key" , "val" );
101
- test .getFunctionName ();
102
93
});
103
94
104
- verify (test ).getFunctionName ();
105
-
106
95
assertThat (AWSXRay .getTraceEntity ().getSubsegments ())
107
96
.hasSize (1 )
108
- .allSatisfy (subsegment ->
109
- {
97
+ .allSatisfy (subsegment -> {
110
98
assertThat (subsegment .getName ())
111
99
.isEqualTo ("## testSubSegment" );
112
100
@@ -142,21 +130,14 @@ void shouldAddAnnotationIfValidCharactersInKey() {
142
130
143
131
@ Test
144
132
void shouldInvokeCodeBlockWrappedWithinNamespacedSubsegment () {
145
- Context test = mock (Context .class );
146
-
147
- TracingUtils .withSubsegment ("testNamespace" , "testSubSegment" , subsegment ->
148
- {
133
+ TracingUtils .withSubsegment ("testNamespace" , "testSubSegment" , subsegment -> {
149
134
subsegment .putAnnotation ("key" , "val" );
150
135
subsegment .putMetadata ("key" , "val" );
151
- test .getFunctionName ();
152
136
});
153
137
154
- verify (test ).getFunctionName ();
155
-
156
138
assertThat (AWSXRay .getTraceEntity ().getSubsegments ())
157
139
.hasSize (1 )
158
- .allSatisfy (subsegment ->
159
- {
140
+ .allSatisfy (subsegment -> {
160
141
assertThat (subsegment .getName ())
161
142
.isEqualTo ("## testSubSegment" );
162
143
@@ -174,25 +155,18 @@ void shouldInvokeCodeBlockWrappedWithinNamespacedSubsegment() {
174
155
175
156
@ Test
176
157
void shouldInvokeCodeBlockWrappedWithinEntitySubsegment () throws InterruptedException {
177
- Context test = mock (Context .class );
178
-
179
158
Entity traceEntity = AWSXRay .getTraceEntity ();
180
159
181
- Thread thread = new Thread (() -> withEntitySubsegment ("testSubSegment" , traceEntity , subsegment ->
182
- {
160
+ Thread thread = new Thread (() -> withEntitySubsegment ("testSubSegment" , traceEntity , subsegment -> {
183
161
subsegment .putAnnotation ("key" , "val" );
184
- test .getFunctionName ();
185
162
}));
186
163
187
164
thread .start ();
188
165
thread .join ();
189
166
190
- verify (test ).getFunctionName ();
191
-
192
167
assertThat (AWSXRay .getTraceEntity ().getSubsegments ())
193
168
.hasSize (1 )
194
- .allSatisfy (subsegment ->
195
- {
169
+ .allSatisfy (subsegment -> {
196
170
assertThat (subsegment .getName ())
197
171
.isEqualTo ("## testSubSegment" );
198
172
@@ -207,26 +181,19 @@ void shouldInvokeCodeBlockWrappedWithinEntitySubsegment() throws InterruptedExce
207
181
208
182
@ Test
209
183
void shouldInvokeCodeBlockWrappedWithinNamespacedEntitySubsegment () throws InterruptedException {
210
- Context test = mock (Context .class );
211
-
212
184
Entity traceEntity = AWSXRay .getTraceEntity ();
213
185
214
- Thread thread =
215
- new Thread (() -> withEntitySubsegment ("testNamespace" , "testSubSegment" , traceEntity , subsegment ->
216
- {
186
+ Thread thread = new Thread (
187
+ () -> withEntitySubsegment ("testNamespace" , "testSubSegment" , traceEntity , subsegment -> {
217
188
subsegment .putAnnotation ("key" , "val" );
218
- test .getFunctionName ();
219
189
}));
220
190
221
191
thread .start ();
222
192
thread .join ();
223
193
224
- verify (test ).getFunctionName ();
225
-
226
194
assertThat (AWSXRay .getTraceEntity ().getSubsegments ())
227
195
.hasSize (1 )
228
- .allSatisfy (subsegment ->
229
- {
196
+ .allSatisfy (subsegment -> {
230
197
assertThat (subsegment .getName ())
231
198
.isEqualTo ("## testSubSegment" );
232
199
0 commit comments