1
+ /*
2
+ * Copyright 2022 NAVER Corp.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .navercorp .pinpoint .bootstrap .plugin .reactor ;
18
+
19
+ import com .navercorp .pinpoint .bootstrap .context .AsyncContext ;
20
+ import org .junit .Test ;
21
+
22
+ import static org .junit .Assert .*;
23
+ import static org .mockito .Mockito .mock ;
24
+
25
+ public class FluxAndMonoOperatorConstructorInterceptorTest {
26
+
27
+ @ Test
28
+ public void arg0ContainAsyncContext () {
29
+ AsyncContext mockAsyncContext = mock (AsyncContext .class );
30
+ MockAsyncContextAndReactorContextImpl target = new MockAsyncContextAndReactorContextImpl ();
31
+ MockAsyncContextAndReactorContextImpl arg0 = new MockAsyncContextAndReactorContextImpl ();
32
+ FluxAndMonoOperatorConstructorInterceptor interceptor = new FluxAndMonoOperatorConstructorInterceptor ();
33
+
34
+ // Set asyncContext to target
35
+ arg0 ._$PINPOINT$_setAsyncContext (mockAsyncContext );
36
+ interceptor .after (target , new Object []{arg0 }, new Object (), null );
37
+
38
+ assertNull (target ._$PINPOINT$_getAsyncContext ());
39
+ assertNotNull (target ._$PINPOINT$_getReactorContext ());
40
+ assertEquals (target ._$PINPOINT$_getReactorContext (), mockAsyncContext );
41
+ }
42
+
43
+ @ Test
44
+ public void arg0ContainReactorContext () {
45
+ AsyncContext mockAsyncContext = mock (AsyncContext .class );
46
+ MockAsyncContextAndReactorContextImpl target = new MockAsyncContextAndReactorContextImpl ();
47
+ MockAsyncContextAndReactorContextImpl arg0 = new MockAsyncContextAndReactorContextImpl ();
48
+ FluxAndMonoOperatorConstructorInterceptor interceptor = new FluxAndMonoOperatorConstructorInterceptor ();
49
+
50
+ // Set asyncContext to target
51
+ arg0 ._$PINPOINT$_setReactorContext (mockAsyncContext );
52
+ interceptor .after (target , new Object []{arg0 }, new Object (), null );
53
+
54
+ assertNull (target ._$PINPOINT$_getAsyncContext ());
55
+ assertNotNull (target ._$PINPOINT$_getReactorContext ());
56
+ assertEquals (target ._$PINPOINT$_getReactorContext (), mockAsyncContext );
57
+ }
58
+
59
+ @ Test
60
+ public void arg0NotContainAsyncContext () {
61
+ MockAsyncContextAndReactorContextImpl target = new MockAsyncContextAndReactorContextImpl ();
62
+ MockAsyncContextAndReactorContextImpl arg0 = new MockAsyncContextAndReactorContextImpl ();
63
+ FluxAndMonoOperatorConstructorInterceptor interceptor = new FluxAndMonoOperatorConstructorInterceptor ();
64
+
65
+ // Not set asyncContext to target
66
+ interceptor .after (target , new Object []{arg0 }, new Object (), null );
67
+
68
+ assertNull (target ._$PINPOINT$_getAsyncContext ());
69
+ assertNull (target ._$PINPOINT$_getReactorContext ());
70
+ }
71
+
72
+ @ Test
73
+ public void arg1ContainAsyncContext () {
74
+ AsyncContext mockAsyncContext = mock (AsyncContext .class );
75
+ MockAsyncContextAndReactorContextImpl target = new MockAsyncContextAndReactorContextImpl ();
76
+ MockAsyncContextAndReactorContextImpl arg0 = new MockAsyncContextAndReactorContextImpl ();
77
+ MockAsyncContextAndReactorContextImpl arg1 = new MockAsyncContextAndReactorContextImpl ();
78
+ FluxAndMonoOperatorConstructorInterceptor interceptor = new FluxAndMonoOperatorConstructorInterceptor ();
79
+
80
+ // Set asyncContext to target
81
+ arg1 ._$PINPOINT$_setAsyncContext (mockAsyncContext );
82
+ interceptor .after (target , new Object []{arg0 , arg1 }, new Object (), null );
83
+
84
+ assertNotNull (target ._$PINPOINT$_getAsyncContext ());
85
+ assertEquals (target ._$PINPOINT$_getAsyncContext (), mockAsyncContext );
86
+ assertNotNull (target ._$PINPOINT$_getReactorContext ());
87
+ assertEquals (target ._$PINPOINT$_getReactorContext (), mockAsyncContext );
88
+ }
89
+
90
+ @ Test
91
+ public void throwableIsNotNull () {
92
+ AsyncContext mockAsyncContext = mock (AsyncContext .class );
93
+ MockAsyncContextAndReactorContextImpl target = new MockAsyncContextAndReactorContextImpl ();
94
+ MockAsyncContextAndReactorContextImpl arg0 = new MockAsyncContextAndReactorContextImpl ();
95
+ Throwable throwable = new Throwable ("ERROR" );
96
+ FluxAndMonoOperatorConstructorInterceptor interceptor = new FluxAndMonoOperatorConstructorInterceptor ();
97
+
98
+ interceptor .after (target , new Object []{arg0 }, new Object (), throwable );
99
+
100
+ assertNull (target ._$PINPOINT$_getAsyncContext ());
101
+ assertNull (target ._$PINPOINT$_getReactorContext ());
102
+ }
103
+ }
0 commit comments