1818
1919import static org .assertj .core .api .Assertions .assertThat ;
2020import static org .mockito .ArgumentMatchers .any ;
21+ import static org .mockito .ArgumentMatchers .anyBoolean ;
2122import static org .mockito .Mockito .mock ;
2223import static org .mockito .Mockito .never ;
2324import static org .mockito .Mockito .verify ;
2728import java .util .Map ;
2829
2930import org .apache .kafka .clients .consumer .Consumer ;
31+ import org .apache .kafka .clients .consumer .ConsumerRecord ;
3032import org .apache .kafka .clients .consumer .ConsumerRecords ;
3133import org .junit .jupiter .api .Test ;
3234
3941 *
4042 * @author Gary Russell
4143 * @author Adrian Chlebosz
44+ * @author Antonin Arquey
45+ * @author Dan Blackney
4246 * @since 2.8
4347 *
4448 */
4549public class CommonDelegatingErrorHandlerTests {
4650
4751 @ Test
48- void testRecordDelegates () {
52+ void testHandleRemainingDelegates () {
4953 var def = mock (CommonErrorHandler .class );
5054 var one = mock (CommonErrorHandler .class );
5155 var two = mock (CommonErrorHandler .class );
@@ -69,7 +73,7 @@ void testRecordDelegates() {
6973 }
7074
7175 @ Test
72- void testBatchDelegates () {
76+ void testHandleBatchDelegates () {
7377 var def = mock (CommonErrorHandler .class );
7478 var one = mock (CommonErrorHandler .class );
7579 var two = mock (CommonErrorHandler .class );
@@ -92,6 +96,54 @@ void testBatchDelegates() {
9296 verify (one ).handleBatch (any (), any (), any (), any (), any ());
9397 }
9498
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+
95147 @ Test
96148 void testDelegateForThrowableIsAppliedWhenCauseTraversingIsEnabled () {
97149 var defaultHandler = mock (CommonErrorHandler .class );
0 commit comments