37
37
import java .util .concurrent .ScheduledExecutorService ;
38
38
import java .util .concurrent .ScheduledThreadPoolExecutor ;
39
39
import java .util .function .Consumer ;
40
+ import java .util .function .Function ;
40
41
import java .util .function .Supplier ;
41
42
import java .util .function .UnaryOperator ;
42
43
@@ -123,6 +124,7 @@ public JdaTester() {
123
124
doReturn (APPLICATION_ID ).when (selfUser ).getApplicationIdLong ();
124
125
doReturn (selfUser ).when (jda ).getSelfUser ();
125
126
when (jda .getGuildChannelById (anyLong ())).thenReturn (textChannel );
127
+ when (jda .getTextChannelById (anyLong ())).thenReturn (textChannel );
126
128
when (jda .getPrivateChannelById (anyLong ())).thenReturn (privateChannel );
127
129
when (jda .getGuildById (anyLong ())).thenReturn (guild );
128
130
when (jda .getEntityBuilder ()).thenReturn (entityBuilder );
@@ -147,13 +149,19 @@ public JdaTester() {
147
149
auditableRestAction = (AuditableRestActionImpl <Void >) mock (AuditableRestActionImpl .class );
148
150
doNothing ().when (auditableRestAction ).queue ();
149
151
150
- doNothing ().when (messageAction ).queue ();
151
-
152
152
doReturn (everyoneRole ).when (guild ).getPublicRole ();
153
153
doReturn (selfMember ).when (guild ).getMember (selfUser );
154
154
doReturn (member ).when (guild ).getMember (not (eq (selfUser )));
155
155
156
+ RestAction <User > userAction = createSucceededActionMock (member .getUser ());
157
+ when (jda .retrieveUserById (anyLong ())).thenReturn (userAction );
158
+
156
159
doReturn (null ).when (textChannel ).retrieveMessageById (any ());
160
+ doReturn (messageAction ).when (textChannel ).sendMessageEmbeds (any (), any ());
161
+ doReturn (messageAction ).when (textChannel ).sendMessageEmbeds (any ());
162
+
163
+ doNothing ().when (messageAction ).queue ();
164
+ when (messageAction .content (any ())).thenReturn (messageAction );
157
165
}
158
166
159
167
/**
@@ -319,11 +327,25 @@ public JdaTester() {
319
327
successConsumer .accept (t );
320
328
return null ;
321
329
};
330
+ Answer <RestAction <?>> mapExecution = invocation -> {
331
+ Function <? super T , ?> mapFunction = invocation .getArgument (0 );
332
+ Object result = mapFunction .apply (t );
333
+ return createSucceededActionMock (result );
334
+ };
335
+ Answer <RestAction <?>> flatMapExecution = invocation -> {
336
+ Function <? super T , RestAction <?>> flatMapFunction = invocation .getArgument (0 );
337
+ return flatMapFunction .apply (t );
338
+ };
322
339
323
340
doNothing ().when (action ).queue ();
324
341
325
342
doAnswer (successExecution ).when (action ).queue (any ());
326
343
doAnswer (successExecution ).when (action ).queue (any (), any ());
344
+ when (action .onErrorMap (any ())).thenReturn (action );
345
+ when (action .onErrorMap (any (), any ())).thenReturn (action );
346
+
347
+ doAnswer (mapExecution ).when (action ).map (any ());
348
+ doAnswer (flatMapExecution ).when (action ).flatMap (any ());
327
349
328
350
return action ;
329
351
}
0 commit comments