18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
20
import static org .mockito .ArgumentMatchers .any ;
21
+ import static org .mockito .ArgumentMatchers .anyBoolean ;
21
22
import static org .mockito .Mockito .mock ;
22
23
import static org .mockito .Mockito .never ;
23
24
import static org .mockito .Mockito .verify ;
27
28
import java .util .Map ;
28
29
29
30
import org .apache .kafka .clients .consumer .Consumer ;
31
+ import org .apache .kafka .clients .consumer .ConsumerRecord ;
30
32
import org .apache .kafka .clients .consumer .ConsumerRecords ;
31
33
import org .junit .jupiter .api .Test ;
32
34
39
41
*
40
42
* @author Gary Russell
41
43
* @author Adrian Chlebosz
44
+ * @author Antonin Arquey
45
+ * @author Dan Blackney
42
46
* @since 2.8
43
47
*
44
48
*/
45
49
public class CommonDelegatingErrorHandlerTests {
46
50
47
51
@ Test
48
- void testRecordDelegates () {
52
+ void testHandleRemainingDelegates () {
49
53
var def = mock (CommonErrorHandler .class );
50
54
var one = mock (CommonErrorHandler .class );
51
55
var two = mock (CommonErrorHandler .class );
@@ -69,7 +73,7 @@ void testRecordDelegates() {
69
73
}
70
74
71
75
@ Test
72
- void testBatchDelegates () {
76
+ void testHandleBatchDelegates () {
73
77
var def = mock (CommonErrorHandler .class );
74
78
var one = mock (CommonErrorHandler .class );
75
79
var two = mock (CommonErrorHandler .class );
@@ -92,6 +96,54 @@ void testBatchDelegates() {
92
96
verify (one ).handleBatch (any (), any (), any (), any (), any ());
93
97
}
94
98
99
+ @ Test
100
+ void testHandleOtherExceptionDelegates () {
101
+ var def = mock (CommonErrorHandler .class );
102
+ var one = mock (CommonErrorHandler .class );
103
+ var two = mock (CommonErrorHandler .class );
104
+ var three = mock (CommonErrorHandler .class );
105
+ var eh = new CommonDelegatingErrorHandler (def );
106
+ eh .setErrorHandlers (Map .of (IllegalStateException .class , one , IllegalArgumentException .class , two ));
107
+ eh .addDelegate (RuntimeException .class , three );
108
+
109
+ eh .handleOtherException (wrap (new IOException ()), mock (Consumer .class ),
110
+ mock (MessageListenerContainer .class ), true );
111
+ verify (def ).handleOtherException (any (), any (), any (), anyBoolean ());
112
+ eh .handleOtherException (wrap (new KafkaException ("test" )), mock (Consumer .class ),
113
+ mock (MessageListenerContainer .class ), true );
114
+ verify (three ).handleOtherException (any (), any (), any (), anyBoolean ());
115
+ eh .handleOtherException (wrap (new IllegalArgumentException ()), mock (Consumer .class ),
116
+ mock (MessageListenerContainer .class ), true );
117
+ verify (two ).handleOtherException (any (), any (), any (), anyBoolean ());
118
+ eh .handleOtherException (wrap (new IllegalStateException ()), mock (Consumer .class ),
119
+ mock (MessageListenerContainer .class ), true );
120
+ verify (one ).handleOtherException (any (), any (), any (), anyBoolean ());
121
+ }
122
+
123
+ @ Test
124
+ void testHandleOneDelegates () {
125
+ var def = mock (CommonErrorHandler .class );
126
+ var one = mock (CommonErrorHandler .class );
127
+ var two = mock (CommonErrorHandler .class );
128
+ var three = mock (CommonErrorHandler .class );
129
+ var eh = new CommonDelegatingErrorHandler (def );
130
+ eh .setErrorHandlers (Map .of (IllegalStateException .class , one , IllegalArgumentException .class , two ));
131
+ eh .addDelegate (RuntimeException .class , three );
132
+
133
+ eh .handleOne (wrap (new IOException ()), mock (ConsumerRecord .class ), mock (Consumer .class ),
134
+ mock (MessageListenerContainer .class ));
135
+ verify (def ).handleOne (any (), any (), any (), any ());
136
+ eh .handleOne (wrap (new KafkaException ("test" )), mock (ConsumerRecord .class ), mock (Consumer .class ),
137
+ mock (MessageListenerContainer .class ));
138
+ verify (three ).handleOne (any (), any (), any (), any ());
139
+ eh .handleOne (wrap (new IllegalArgumentException ()), mock (ConsumerRecord .class ), mock (Consumer .class ),
140
+ mock (MessageListenerContainer .class ));
141
+ verify (two ).handleOne (any (), any (), any (), any ());
142
+ eh .handleOne (wrap (new IllegalStateException ()), mock (ConsumerRecord .class ), mock (Consumer .class ),
143
+ mock (MessageListenerContainer .class ));
144
+ verify (one ).handleOne (any (), any (), any (), any ());
145
+ }
146
+
95
147
@ Test
96
148
void testDelegateForThrowableIsAppliedWhenCauseTraversingIsEnabled () {
97
149
var defaultHandler = mock (CommonErrorHandler .class );
0 commit comments