|
@@ -0,0 +1,441 @@
|
|
1
|
+package com.xxl.job.core.biz.impl;
|
|
2
|
+
|
|
3
|
+import static org.mockito.AdditionalMatchers.or;
|
|
4
|
+import static org.mockito.Matchers.anyInt;
|
|
5
|
+import static org.mockito.Matchers.anyLong;
|
|
6
|
+import static org.mockito.Matchers.isA;
|
|
7
|
+import static org.mockito.Matchers.isNull;
|
|
8
|
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
|
9
|
+
|
|
10
|
+import com.diffblue.deeptestutils.Reflector;
|
|
11
|
+import com.diffblue.deeptestutils.mock.DTUMemberMatcher;
|
|
12
|
+import com.xxl.job.core.biz.model.LogResult;
|
|
13
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
14
|
+import com.xxl.job.core.biz.model.TriggerParam;
|
|
15
|
+import com.xxl.job.core.executor.XxlJobExecutor;
|
|
16
|
+import com.xxl.job.core.glue.GlueTypeEnum;
|
|
17
|
+import com.xxl.job.core.handler.IJobHandler;
|
|
18
|
+import com.xxl.job.core.handler.impl.ScriptJobHandler;
|
|
19
|
+import com.xxl.job.core.log.XxlJobFileAppender;
|
|
20
|
+import com.xxl.job.core.thread.JobThread;
|
|
21
|
+import org.junit.Assert;
|
|
22
|
+import org.junit.Rule;
|
|
23
|
+import org.junit.Test;
|
|
24
|
+import org.junit.rules.ExpectedException;
|
|
25
|
+import org.junit.rules.Timeout;
|
|
26
|
+import org.junit.runner.RunWith;
|
|
27
|
+import org.powermock.api.mockito.PowerMockito;
|
|
28
|
+import org.powermock.api.mockito.expectation.PowerMockitoStubber;
|
|
29
|
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
|
30
|
+import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
31
|
+import org.powermock.modules.junit4.PowerMockRunner;
|
|
32
|
+
|
|
33
|
+import java.lang.reflect.InvocationTargetException;
|
|
34
|
+import java.lang.reflect.Method;
|
|
35
|
+import java.util.Date;
|
|
36
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
37
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
38
|
+
|
|
39
|
+@RunWith(PowerMockRunner.class)
|
|
40
|
+@PowerMockIgnore({"javax.management.*"})
|
|
41
|
+public class ExecutorBizImplTest {
|
|
42
|
+
|
|
43
|
+ @Rule public final ExpectedException thrown = ExpectedException.none();
|
|
44
|
+ @Rule public final Timeout globalTimeout = new Timeout(10000);
|
|
45
|
+
|
|
46
|
+ /* testedClasses: ExecutorBizImpl */
|
|
47
|
+ // Test written by Diffblue Cover.
|
|
48
|
+ @Test
|
|
49
|
+ public void beatOutputNotNull() {
|
|
50
|
+
|
|
51
|
+ // Arrange
|
|
52
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
53
|
+
|
|
54
|
+ // Act
|
|
55
|
+ final ReturnT<String> retval = objectUnderTest.beat();
|
|
56
|
+
|
|
57
|
+ // Assert result
|
|
58
|
+ Assert.assertNotNull(retval);
|
|
59
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
60
|
+ Assert.assertEquals(200, retval.getCode());
|
|
61
|
+ Assert.assertNull(retval.getMsg());
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ // Test written by Diffblue Cover.
|
|
65
|
+
|
|
66
|
+ @Test
|
|
67
|
+ public void constructorOutputVoid() {
|
|
68
|
+
|
|
69
|
+ // Act, creating object to test constructor
|
|
70
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
71
|
+
|
|
72
|
+ // Method returns void, testing that no exception is thrown
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ // Test written by Diffblue Cover.
|
|
76
|
+ @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
77
|
+ @Test
|
|
78
|
+ public void idleBeatInputZeroOutputNotNull() throws Exception, InvocationTargetException {
|
|
79
|
+
|
|
80
|
+ // Arrange
|
|
81
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
82
|
+ final int jobId = 0;
|
|
83
|
+ final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
|
|
84
|
+ final JobThread jobThread =
|
|
85
|
+ (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
|
|
86
|
+ Reflector.setField(jobThread, "stopReason", null);
|
|
87
|
+ Reflector.setField(jobThread, "running", true);
|
|
88
|
+ Reflector.setField(jobThread, "jobId", 0);
|
|
89
|
+ Reflector.setField(jobThread, "idleTimes", 0);
|
|
90
|
+ Reflector.setField(jobThread, "toStop", false);
|
|
91
|
+ Reflector.setField(jobThread, "triggerQueue", null);
|
|
92
|
+ Reflector.setField(jobThread, "handler", null);
|
|
93
|
+ Reflector.setField(jobThread, "triggerLogIdSet", null);
|
|
94
|
+ final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
|
|
95
|
+ PowerMockito.doReturn(jobThread)
|
|
96
|
+ .when(concurrentHashMap1, getMethod)
|
|
97
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
98
|
+ final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
|
|
99
|
+ PowerMockito.whenNew(ConcurrentHashMap.class)
|
|
100
|
+ .withNoArguments()
|
|
101
|
+ .thenReturn(concurrentHashMap)
|
|
102
|
+ .thenReturn(concurrentHashMap1);
|
|
103
|
+
|
|
104
|
+ // Act
|
|
105
|
+ final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
|
|
106
|
+
|
|
107
|
+ // Assert result
|
|
108
|
+ Assert.assertNotNull(retval);
|
|
109
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
110
|
+ Assert.assertEquals(500, retval.getCode());
|
|
111
|
+ Assert.assertEquals("job thread is running or has trigger queue.", retval.getMsg());
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ // Test written by Diffblue Cover.
|
|
115
|
+ @PrepareForTest({LinkedBlockingQueue.class, ExecutorBizImpl.class, ConcurrentHashMap.class,
|
|
116
|
+ XxlJobExecutor.class})
|
|
117
|
+ @Test
|
|
118
|
+ public void
|
|
119
|
+ idleBeatInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
|
|
120
|
+
|
|
121
|
+ // Arrange
|
|
122
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
123
|
+ final int jobId = 0;
|
|
124
|
+ final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
|
|
125
|
+ final JobThread jobThread =
|
|
126
|
+ (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
|
|
127
|
+ Reflector.setField(jobThread, "stopReason", null);
|
|
128
|
+ Reflector.setField(jobThread, "running", false);
|
|
129
|
+ Reflector.setField(jobThread, "jobId", 0);
|
|
130
|
+ Reflector.setField(jobThread, "idleTimes", 0);
|
|
131
|
+ Reflector.setField(jobThread, "toStop", false);
|
|
132
|
+ final LinkedBlockingQueue linkedBlockingQueue = PowerMockito.mock(LinkedBlockingQueue.class);
|
|
133
|
+ final Method sizeMethod = DTUMemberMatcher.method(LinkedBlockingQueue.class, "size");
|
|
134
|
+ PowerMockito.doReturn(0).when(linkedBlockingQueue, sizeMethod).withNoArguments();
|
|
135
|
+ Reflector.setField(jobThread, "triggerQueue", linkedBlockingQueue);
|
|
136
|
+ Reflector.setField(jobThread, "handler", null);
|
|
137
|
+ Reflector.setField(jobThread, "triggerLogIdSet", null);
|
|
138
|
+ final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
|
|
139
|
+ PowerMockito.doReturn(jobThread)
|
|
140
|
+ .when(concurrentHashMap1, getMethod)
|
|
141
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
142
|
+ final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
|
|
143
|
+ PowerMockito.whenNew(ConcurrentHashMap.class)
|
|
144
|
+ .withNoArguments()
|
|
145
|
+ .thenReturn(concurrentHashMap)
|
|
146
|
+ .thenReturn(concurrentHashMap1);
|
|
147
|
+
|
|
148
|
+ // Act
|
|
149
|
+ final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
|
|
150
|
+
|
|
151
|
+ // Assert result
|
|
152
|
+ Assert.assertNotNull(retval);
|
|
153
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
154
|
+ Assert.assertEquals(200, retval.getCode());
|
|
155
|
+ Assert.assertNull(retval.getMsg());
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ // Test written by Diffblue Cover.
|
|
159
|
+ @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
160
|
+ @Test
|
|
161
|
+ public void idleBeatInputZeroOutputNotNull3() throws Exception, InvocationTargetException {
|
|
162
|
+
|
|
163
|
+ // Arrange
|
|
164
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
165
|
+ final int jobId = 0;
|
|
166
|
+ final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
|
|
167
|
+ final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
|
|
168
|
+ PowerMockito.doReturn(null)
|
|
169
|
+ .when(concurrentHashMap1, getMethod)
|
|
170
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
171
|
+ final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
|
|
172
|
+ PowerMockito.whenNew(ConcurrentHashMap.class)
|
|
173
|
+ .withNoArguments()
|
|
174
|
+ .thenReturn(concurrentHashMap)
|
|
175
|
+ .thenReturn(concurrentHashMap1);
|
|
176
|
+
|
|
177
|
+ // Act
|
|
178
|
+ final ReturnT<String> retval = objectUnderTest.idleBeat(jobId);
|
|
179
|
+
|
|
180
|
+ // Assert result
|
|
181
|
+ Assert.assertNotNull(retval);
|
|
182
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
183
|
+ Assert.assertEquals(200, retval.getCode());
|
|
184
|
+ Assert.assertNull(retval.getMsg());
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ // Test written by Diffblue Cover.
|
|
188
|
+ @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
189
|
+ @Test
|
|
190
|
+ public void killInputZeroOutputNotNull() throws Exception, InvocationTargetException {
|
|
191
|
+
|
|
192
|
+ // Arrange
|
|
193
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
194
|
+ final int jobId = 0;
|
|
195
|
+ final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
|
|
196
|
+ final JobThread jobThread =
|
|
197
|
+ (JobThread)Reflector.getInstance("com.xxl.job.core.thread.JobThread");
|
|
198
|
+ Reflector.setField(jobThread, "stopReason", null);
|
|
199
|
+ Reflector.setField(jobThread, "running", false);
|
|
200
|
+ Reflector.setField(jobThread, "jobId", 0);
|
|
201
|
+ Reflector.setField(jobThread, "idleTimes", 0);
|
|
202
|
+ Reflector.setField(jobThread, "toStop", false);
|
|
203
|
+ Reflector.setField(jobThread, "triggerQueue", null);
|
|
204
|
+ Reflector.setField(jobThread, "handler", null);
|
|
205
|
+ Reflector.setField(jobThread, "triggerLogIdSet", null);
|
|
206
|
+ final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
|
|
207
|
+ PowerMockito.doReturn(jobThread)
|
|
208
|
+ .when(concurrentHashMap1, getMethod)
|
|
209
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
210
|
+ final Method removeMethod =
|
|
211
|
+ DTUMemberMatcher.method(ConcurrentHashMap.class, "remove", Object.class);
|
|
212
|
+ PowerMockito.doReturn(null)
|
|
213
|
+ .when(concurrentHashMap1, removeMethod)
|
|
214
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
215
|
+ final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
|
|
216
|
+ PowerMockito.whenNew(ConcurrentHashMap.class)
|
|
217
|
+ .withNoArguments()
|
|
218
|
+ .thenReturn(concurrentHashMap)
|
|
219
|
+ .thenReturn(concurrentHashMap1);
|
|
220
|
+
|
|
221
|
+ // Act
|
|
222
|
+ final ReturnT<String> retval = objectUnderTest.kill(jobId);
|
|
223
|
+
|
|
224
|
+ // Assert result
|
|
225
|
+ Assert.assertNotNull(retval);
|
|
226
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
227
|
+ Assert.assertEquals(200, retval.getCode());
|
|
228
|
+ Assert.assertNull(retval.getMsg());
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ // Test written by Diffblue Cover.
|
|
232
|
+ @PrepareForTest({ExecutorBizImpl.class, ConcurrentHashMap.class, XxlJobExecutor.class})
|
|
233
|
+ @Test
|
|
234
|
+ public void killInputZeroOutputNotNull2() throws Exception, InvocationTargetException {
|
|
235
|
+
|
|
236
|
+ // Arrange
|
|
237
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
238
|
+ final int jobId = 0;
|
|
239
|
+ final ConcurrentHashMap concurrentHashMap1 = PowerMockito.mock(ConcurrentHashMap.class);
|
|
240
|
+ final Method getMethod = DTUMemberMatcher.method(ConcurrentHashMap.class, "get", Object.class);
|
|
241
|
+ PowerMockito.doReturn(null)
|
|
242
|
+ .when(concurrentHashMap1, getMethod)
|
|
243
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)));
|
|
244
|
+ final ConcurrentHashMap concurrentHashMap = PowerMockito.mock(ConcurrentHashMap.class);
|
|
245
|
+ PowerMockito.whenNew(ConcurrentHashMap.class)
|
|
246
|
+ .withNoArguments()
|
|
247
|
+ .thenReturn(concurrentHashMap)
|
|
248
|
+ .thenReturn(concurrentHashMap1);
|
|
249
|
+
|
|
250
|
+ // Act
|
|
251
|
+ final ReturnT<String> retval = objectUnderTest.kill(jobId);
|
|
252
|
+
|
|
253
|
+ // Assert result
|
|
254
|
+ Assert.assertNotNull(retval);
|
|
255
|
+ Assert.assertNull(((ReturnT<String>)retval).getContent());
|
|
256
|
+ Assert.assertEquals(200, retval.getCode());
|
|
257
|
+ Assert.assertEquals("job thread aleady killed.", retval.getMsg());
|
|
258
|
+ }
|
|
259
|
+
|
|
260
|
+ // Test written by Diffblue Cover.
|
|
261
|
+ @PrepareForTest({XxlJobFileAppender.class, ExecutorBizImpl.class})
|
|
262
|
+ @Test
|
|
263
|
+ public void logInputZeroZeroZeroOutputNotNull() throws Exception, InvocationTargetException {
|
|
264
|
+
|
|
265
|
+ // Setup mocks
|
|
266
|
+ PowerMockito.mockStatic(XxlJobFileAppender.class);
|
|
267
|
+
|
|
268
|
+ // Arrange
|
|
269
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
270
|
+ final long logDateTim = 0L;
|
|
271
|
+ final int logId = 0;
|
|
272
|
+ final int fromLineNum = 0;
|
|
273
|
+ final ReturnT returnT = PowerMockito.mock(ReturnT.class);
|
|
274
|
+ PowerMockito.whenNew(ReturnT.class)
|
|
275
|
+ .withParameterTypes(Object.class)
|
|
276
|
+ .withArguments(or(isA(Object.class), isNull(Object.class)))
|
|
277
|
+ .thenReturn(returnT);
|
|
278
|
+ final Date date = PowerMockito.mock(Date.class);
|
|
279
|
+ Reflector.setField(date, "fastTime", 1_515_585_600_000L);
|
|
280
|
+ PowerMockito.whenNew(Date.class)
|
|
281
|
+ .withParameterTypes(long.class)
|
|
282
|
+ .withArguments(anyLong())
|
|
283
|
+ .thenReturn(date);
|
|
284
|
+ final LogResult logResult =
|
|
285
|
+ (LogResult)Reflector.getInstance("com.xxl.job.core.biz.model.LogResult");
|
|
286
|
+ final Method readLogMethod =
|
|
287
|
+ DTUMemberMatcher.method(XxlJobFileAppender.class, "readLog", String.class, int.class);
|
|
288
|
+ PowerMockito.doReturn(logResult)
|
|
289
|
+ .when(XxlJobFileAppender.class, readLogMethod)
|
|
290
|
+ .withArguments(or(isA(String.class), isNull(String.class)), anyInt());
|
|
291
|
+ final Method makeLogFileNameMethod =
|
|
292
|
+ DTUMemberMatcher.method(XxlJobFileAppender.class, "makeLogFileName", Date.class, int.class);
|
|
293
|
+ PowerMockito.doReturn("?")
|
|
294
|
+ .when(XxlJobFileAppender.class, makeLogFileNameMethod)
|
|
295
|
+ .withArguments(or(isA(Date.class), isNull(Date.class)), anyInt());
|
|
296
|
+
|
|
297
|
+ // Act
|
|
298
|
+ final ReturnT<LogResult> retval = objectUnderTest.log(logDateTim, logId, fromLineNum);
|
|
299
|
+
|
|
300
|
+ // Assert result
|
|
301
|
+ Assert.assertNotNull(retval);
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ // Test written by Diffblue Cover.
|
|
305
|
+ @PrepareForTest({XxlJobExecutor.class, GlueTypeEnum.class, JobThread.class, ExecutorBizImpl.class,
|
|
306
|
+ TriggerParam.class})
|
|
307
|
+ @Test
|
|
308
|
+ public void
|
|
309
|
+ runInputNotNullOutputNotNull() throws Exception, InvocationTargetException {
|
|
310
|
+
|
|
311
|
+ // Setup mocks
|
|
312
|
+ PowerMockito.mockStatic(XxlJobExecutor.class);
|
|
313
|
+ PowerMockito.mockStatic(GlueTypeEnum.class);
|
|
314
|
+
|
|
315
|
+ // Arrange
|
|
316
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
317
|
+ final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
|
|
318
|
+ final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
|
|
319
|
+ PowerMockito.doReturn(0).when(triggerParam, getJobIdMethod).withNoArguments();
|
|
320
|
+ final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
|
|
321
|
+ ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
|
|
322
|
+ .when(triggerParam, getGlueTypeMethod)
|
|
323
|
+ .withNoArguments();
|
|
324
|
+ final ReturnT returnT = PowerMockito.mock(ReturnT.class);
|
|
325
|
+ PowerMockito.whenNew(ReturnT.class)
|
|
326
|
+ .withParameterTypes(int.class, String.class)
|
|
327
|
+ .withArguments(anyInt(), or(isA(String.class), isNull(String.class)))
|
|
328
|
+ .thenReturn(returnT);
|
|
329
|
+ final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
|
|
330
|
+ final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
|
|
331
|
+ PowerMockito.doReturn(false).when(glueTypeEnum, isScriptMethod).withNoArguments();
|
|
332
|
+ final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
|
|
333
|
+ PowerMockito.doReturn(glueTypeEnum)
|
|
334
|
+ .when(GlueTypeEnum.class, matchMethod)
|
|
335
|
+ .withArguments(or(isA(String.class), isNull(String.class)));
|
|
336
|
+ final JobThread jobThread = PowerMockito.mock(JobThread.class);
|
|
337
|
+ final IJobHandler iJobHandler =
|
|
338
|
+ (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
|
|
339
|
+ final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
|
|
340
|
+ PowerMockito.doReturn(iJobHandler).when(jobThread, getHandlerMethod).withNoArguments();
|
|
341
|
+ final Method loadJobThreadMethod =
|
|
342
|
+ DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
|
|
343
|
+ PowerMockito.doReturn(jobThread)
|
|
344
|
+ .when(XxlJobExecutor.class, loadJobThreadMethod)
|
|
345
|
+ .withArguments(anyInt());
|
|
346
|
+
|
|
347
|
+ // Act
|
|
348
|
+ final ReturnT<String> retval = objectUnderTest.run(triggerParam);
|
|
349
|
+
|
|
350
|
+ // Assert result
|
|
351
|
+ Assert.assertNotNull(retval);
|
|
352
|
+ }
|
|
353
|
+
|
|
354
|
+ // Test written by Diffblue Cover.
|
|
355
|
+ @PrepareForTest({ExecutorBizImpl.class, XxlJobExecutor.class, TriggerParam.class, JobThread.class,
|
|
356
|
+ GlueTypeEnum.class})
|
|
357
|
+ @Test
|
|
358
|
+ public void
|
|
359
|
+ runInputNotNullOutputNotNull2() throws Exception, InvocationTargetException {
|
|
360
|
+
|
|
361
|
+ // Setup mocks
|
|
362
|
+ PowerMockito.mockStatic(GlueTypeEnum.class);
|
|
363
|
+ PowerMockito.mockStatic(XxlJobExecutor.class);
|
|
364
|
+
|
|
365
|
+ // Arrange
|
|
366
|
+ final ExecutorBizImpl objectUnderTest = new ExecutorBizImpl();
|
|
367
|
+ final TriggerParam triggerParam = PowerMockito.mock(TriggerParam.class);
|
|
368
|
+ final Method getJobIdMethod = DTUMemberMatcher.method(TriggerParam.class, "getJobId");
|
|
369
|
+ ((PowerMockitoStubber)PowerMockito.doReturn(0).doReturn(0).doReturn(0))
|
|
370
|
+ .when(triggerParam, getJobIdMethod)
|
|
371
|
+ .withNoArguments();
|
|
372
|
+ final Method getGlueTypeMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueType");
|
|
373
|
+ ((PowerMockitoStubber)PowerMockito.doReturn("?").doReturn("?"))
|
|
374
|
+ .when(triggerParam, getGlueTypeMethod)
|
|
375
|
+ .withNoArguments();
|
|
376
|
+ final Method getGlueUpdatetimeMethod =
|
|
377
|
+ DTUMemberMatcher.method(TriggerParam.class, "getGlueUpdatetime");
|
|
378
|
+ PowerMockito.doReturn(0L).when(triggerParam, getGlueUpdatetimeMethod).withNoArguments();
|
|
379
|
+ final Method getGlueSourceMethod = DTUMemberMatcher.method(TriggerParam.class, "getGlueSource");
|
|
380
|
+ PowerMockito.doReturn("?").when(triggerParam, getGlueSourceMethod).withNoArguments();
|
|
381
|
+ final ScriptJobHandler scriptJobHandler = PowerMockito.mock(ScriptJobHandler.class);
|
|
382
|
+ PowerMockito.whenNew(ScriptJobHandler.class)
|
|
383
|
+ .withParameterTypes(int.class, long.class, String.class, GlueTypeEnum.class)
|
|
384
|
+ .withArguments(anyInt(), anyLong(), or(isA(String.class), isNull(String.class)),
|
|
385
|
+ or(isA(GlueTypeEnum.class), isNull(GlueTypeEnum.class)))
|
|
386
|
+ .thenReturn(scriptJobHandler);
|
|
387
|
+ final JobThread jobThread = PowerMockito.mock(JobThread.class);
|
|
388
|
+ final ReturnT returnT = (ReturnT)Reflector.getInstance("com.xxl.job.core.biz.model.ReturnT");
|
|
389
|
+ final Method pushTriggerQueueMethod =
|
|
390
|
+ DTUMemberMatcher.method(JobThread.class, "pushTriggerQueue", TriggerParam.class);
|
|
391
|
+ PowerMockito.doReturn(returnT)
|
|
392
|
+ .when(jobThread, pushTriggerQueueMethod)
|
|
393
|
+ .withArguments(or(isA(TriggerParam.class), isNull(TriggerParam.class)));
|
|
394
|
+ final Method registJobThreadMethod = DTUMemberMatcher.method(
|
|
395
|
+ XxlJobExecutor.class, "registJobThread", int.class, IJobHandler.class, String.class);
|
|
396
|
+ PowerMockito.doReturn(jobThread)
|
|
397
|
+ .when(XxlJobExecutor.class, registJobThreadMethod)
|
|
398
|
+ .withArguments(anyInt(), or(isA(IJobHandler.class), isNull(IJobHandler.class)),
|
|
399
|
+ or(isA(String.class), isNull(String.class)));
|
|
400
|
+ final GlueTypeEnum glueTypeEnum1 =
|
|
401
|
+ (GlueTypeEnum)Reflector.getInstance("com.xxl.job.core.glue.GlueTypeEnum");
|
|
402
|
+ final GlueTypeEnum glueTypeEnum = PowerMockito.mock(GlueTypeEnum.class);
|
|
403
|
+ final Method isScriptMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "isScript");
|
|
404
|
+ PowerMockito.doReturn(true).when(glueTypeEnum, isScriptMethod).withNoArguments();
|
|
405
|
+ final Method matchMethod = DTUMemberMatcher.method(GlueTypeEnum.class, "match", String.class);
|
|
406
|
+ ((PowerMockitoStubber)PowerMockito.doReturn(glueTypeEnum).doReturn(glueTypeEnum1))
|
|
407
|
+ .when(GlueTypeEnum.class, matchMethod)
|
|
408
|
+ .withArguments(or(isA(String.class), isNull(String.class)));
|
|
409
|
+ final JobThread jobThread1 = PowerMockito.mock(JobThread.class);
|
|
410
|
+ final IJobHandler iJobHandler1 =
|
|
411
|
+ (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
|
|
412
|
+ final IJobHandler iJobHandler =
|
|
413
|
+ (IJobHandler)Reflector.getInstance("com.xxl.job.core.handler.IJobHandler");
|
|
414
|
+ final Method getHandlerMethod = DTUMemberMatcher.method(JobThread.class, "getHandler");
|
|
415
|
+ ((PowerMockitoStubber)PowerMockito.doReturn(iJobHandler).doReturn(iJobHandler1))
|
|
416
|
+ .when(jobThread1, getHandlerMethod)
|
|
417
|
+ .withNoArguments();
|
|
418
|
+ final Method loadJobThreadMethod =
|
|
419
|
+ DTUMemberMatcher.method(XxlJobExecutor.class, "loadJobThread", int.class);
|
|
420
|
+ PowerMockito.doReturn(jobThread1)
|
|
421
|
+ .when(XxlJobExecutor.class, loadJobThreadMethod)
|
|
422
|
+ .withArguments(anyInt());
|
|
423
|
+
|
|
424
|
+ // Act
|
|
425
|
+ final ReturnT<String> retval = objectUnderTest.run(triggerParam);
|
|
426
|
+
|
|
427
|
+ // Assert result
|
|
428
|
+ Assert.assertNotNull(retval);
|
|
429
|
+ }
|
|
430
|
+
|
|
431
|
+ // Test written by Diffblue Cover.
|
|
432
|
+
|
|
433
|
+ @Test
|
|
434
|
+ public void staticInitOutputVoid() throws InvocationTargetException {
|
|
435
|
+
|
|
436
|
+ // Act, using constructor to test static initializer
|
|
437
|
+ final Object constructed = Reflector.getInstance("com.xxl.job.core.biz.impl.ExecutorBizImpl");
|
|
438
|
+
|
|
439
|
+ // Method returns void, testing that no exception is thrown
|
|
440
|
+ }
|
|
441
|
+}
|