Upgraded Mockito
This commit upgrades mockito to the latest currently available version as well as does some additional cleanup.
This commit is contained in:
@@ -27,7 +27,7 @@ import org.springframework.messaging.MessageHandlingException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
package org.springframework.batch.integration.partition;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -30,6 +18,17 @@ import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Will Schipp
|
||||
@@ -65,11 +64,11 @@ public class MessageChannelPartitionHandlerTests {
|
||||
MessagingTemplate operations = mock(MessagingTemplate.class);
|
||||
Message message = mock(Message.class);
|
||||
//when
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5l)));
|
||||
when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5L)));
|
||||
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
|
||||
when(message.getPayload()).thenReturn(Collections.emptyList());
|
||||
when(operations.receive((PollableChannel) anyObject())).thenReturn(message);
|
||||
when(operations.receive((PollableChannel) any())).thenReturn(message);
|
||||
//set
|
||||
messageChannelPartitionHandler.setMessagingOperations(operations);
|
||||
|
||||
@@ -91,9 +90,9 @@ public class MessageChannelPartitionHandlerTests {
|
||||
Message message = mock(Message.class);
|
||||
PollableChannel replyChannel = mock(PollableChannel.class);
|
||||
//when
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5l)));
|
||||
when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5L)));
|
||||
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
|
||||
when(message.getPayload()).thenReturn(Collections.emptyList());
|
||||
when(operations.receive(replyChannel)).thenReturn(message);
|
||||
//set
|
||||
@@ -118,15 +117,15 @@ public class MessageChannelPartitionHandlerTests {
|
||||
MessagingTemplate operations = mock(MessagingTemplate.class);
|
||||
Message message = mock(Message.class);
|
||||
//when
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5l)));
|
||||
when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(new StepExecution("step1", new JobExecution(5L)));
|
||||
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
|
||||
when(message.getPayload()).thenReturn(Collections.emptyList());
|
||||
//set
|
||||
messageChannelPartitionHandler.setMessagingOperations(operations);
|
||||
|
||||
//execute
|
||||
Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
|
||||
messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,17 +133,17 @@ public class MessageChannelPartitionHandlerTests {
|
||||
//execute with no default set
|
||||
messageChannelPartitionHandler = new MessageChannelPartitionHandler();
|
||||
//mock
|
||||
JobExecution jobExecution = new JobExecution(5l, new JobParameters());
|
||||
StepExecution masterStepExecution = new StepExecution("step1", jobExecution, 1l);
|
||||
JobExecution jobExecution = new JobExecution(5L, new JobParameters());
|
||||
StepExecution masterStepExecution = new StepExecution("step1", jobExecution, 1L);
|
||||
StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class);
|
||||
MessagingTemplate operations = mock(MessagingTemplate.class);
|
||||
JobExplorer jobExplorer = mock(JobExplorer.class);
|
||||
//when
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
|
||||
StepExecution partition1 = new StepExecution("step1:partition1", jobExecution, 2l);
|
||||
StepExecution partition2 = new StepExecution("step1:partition2", jobExecution, 3l);
|
||||
StepExecution partition3 = new StepExecution("step1:partition3", jobExecution, 4l);
|
||||
StepExecution partition4 = new StepExecution("step1:partition3", jobExecution, 4l);
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<>();
|
||||
StepExecution partition1 = new StepExecution("step1:partition1", jobExecution, 2L);
|
||||
StepExecution partition2 = new StepExecution("step1:partition2", jobExecution, 3L);
|
||||
StepExecution partition3 = new StepExecution("step1:partition3", jobExecution, 4L);
|
||||
StepExecution partition4 = new StepExecution("step1:partition3", jobExecution, 4L);
|
||||
partition1.setStatus(BatchStatus.COMPLETED);
|
||||
partition2.setStatus(BatchStatus.COMPLETED);
|
||||
partition3.setStatus(BatchStatus.STARTED);
|
||||
@@ -152,14 +151,14 @@ public class MessageChannelPartitionHandlerTests {
|
||||
stepExecutions.add(partition1);
|
||||
stepExecutions.add(partition2);
|
||||
stepExecutions.add(partition3);
|
||||
when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
|
||||
when(jobExplorer.getStepExecution(eq(5l), anyLong())).thenReturn(partition2, partition1, partition3, partition3, partition3, partition3, partition4);
|
||||
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
|
||||
when(jobExplorer.getStepExecution(eq(5L), any(Long.class))).thenReturn(partition2, partition1, partition3, partition3, partition3, partition3, partition4);
|
||||
|
||||
//set
|
||||
messageChannelPartitionHandler.setMessagingOperations(operations);
|
||||
messageChannelPartitionHandler.setJobExplorer(jobExplorer);
|
||||
messageChannelPartitionHandler.setStepName("step1");
|
||||
messageChannelPartitionHandler.setPollInterval(500l);
|
||||
messageChannelPartitionHandler.setPollInterval(500L);
|
||||
messageChannelPartitionHandler.afterPropertiesSet();
|
||||
|
||||
//execute
|
||||
@@ -172,7 +171,7 @@ public class MessageChannelPartitionHandlerTests {
|
||||
assertTrue(executions.contains(partition4));
|
||||
|
||||
//verify
|
||||
verify(operations, times(3)).send((Message) anyObject());
|
||||
verify(operations, times(3)).send(any(Message.class));
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
@@ -180,33 +179,33 @@ public class MessageChannelPartitionHandlerTests {
|
||||
//execute with no default set
|
||||
messageChannelPartitionHandler = new MessageChannelPartitionHandler();
|
||||
//mock
|
||||
JobExecution jobExecution = new JobExecution(5l, new JobParameters());
|
||||
StepExecution masterStepExecution = new StepExecution("step1", jobExecution, 1l);
|
||||
JobExecution jobExecution = new JobExecution(5L, new JobParameters());
|
||||
StepExecution masterStepExecution = new StepExecution("step1", jobExecution, 1L);
|
||||
StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class);
|
||||
MessagingTemplate operations = mock(MessagingTemplate.class);
|
||||
JobExplorer jobExplorer = mock(JobExplorer.class);
|
||||
//when
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
|
||||
StepExecution partition1 = new StepExecution("step1:partition1", jobExecution, 2l);
|
||||
StepExecution partition2 = new StepExecution("step1:partition2", jobExecution, 3l);
|
||||
StepExecution partition3 = new StepExecution("step1:partition3", jobExecution, 4l);
|
||||
HashSet<StepExecution> stepExecutions = new HashSet<>();
|
||||
StepExecution partition1 = new StepExecution("step1:partition1", jobExecution, 2L);
|
||||
StepExecution partition2 = new StepExecution("step1:partition2", jobExecution, 3L);
|
||||
StepExecution partition3 = new StepExecution("step1:partition3", jobExecution, 4L);
|
||||
partition1.setStatus(BatchStatus.COMPLETED);
|
||||
partition2.setStatus(BatchStatus.COMPLETED);
|
||||
partition3.setStatus(BatchStatus.STARTED);
|
||||
stepExecutions.add(partition1);
|
||||
stepExecutions.add(partition2);
|
||||
stepExecutions.add(partition3);
|
||||
when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
|
||||
when(jobExplorer.getStepExecution(eq(5l), anyLong())).thenReturn(partition2, partition1, partition3);
|
||||
when(stepExecutionSplitter.split(any(StepExecution.class), eq(1))).thenReturn(stepExecutions);
|
||||
when(jobExplorer.getStepExecution(eq(5L), any(Long.class))).thenReturn(partition2, partition1, partition3);
|
||||
|
||||
//set
|
||||
messageChannelPartitionHandler.setMessagingOperations(operations);
|
||||
messageChannelPartitionHandler.setJobExplorer(jobExplorer);
|
||||
messageChannelPartitionHandler.setStepName("step1");
|
||||
messageChannelPartitionHandler.setTimeout(1000l);
|
||||
messageChannelPartitionHandler.setTimeout(1000L);
|
||||
messageChannelPartitionHandler.afterPropertiesSet();
|
||||
|
||||
//execute
|
||||
Collection<StepExecution> executions = messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
|
||||
messageChannelPartitionHandler.handle(stepExecutionSplitter, masterStepExecution);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user