Commit 02e50afe authored by cijujoseph's avatar cijujoseph

Updated with some docs

parent cf60b609
......@@ -18,54 +18,77 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ProcessEndExecutionListenerTest {
@Configuration
static class ContextConfiguration {
@Bean
public ProcessEndExecutionListener processEndExecutionListener() {
return new ProcessEndExecutionListener();
}
}
static class ContextConfiguration {
@Bean
public ProcessEndExecutionListener processEndExecutionListener() {
return new ProcessEndExecutionListener();
}
}
@InjectMocks
@Spy
private static ProcessEndExecutionListener processEndExecutionListener;
@Mock
private DelegateExecution execution;
@Before
public void initMocks(){
MockitoAnnotations.initMocks(this);
public void initMocks() {
MockitoAnnotations.initMocks(this);
}
/*
* Testing ProcessEndExecutionListener.notify(DelegateExecution execution)
* method using a mock DelegateExecution created using Mockito library
*/
@Test
public void test() throws Exception {
/*
* Creating a map which will be used during the
* DelegateExecution.getVariable() & DelegateExecution.setVariable()
* calls from ProcessEndExecutionListener as well as from this test
*/
Map<String, Object> variableMap = new HashMap<String, Object>();
/*
* Stub a DelegateExecution.setVariable() call
*/
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arg = invocation.getArguments();
variableMap.put((String) arg[0], arg[1]);
return null;
}
}).when(execution).setVariable(anyString(), any());;
when(execution.getVariable(anyString())).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) {
return (String) variableMap.get(invocation.getArguments()[0]);
}
});
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arg = invocation.getArguments();
variableMap.put((String) arg[0], arg[1]);
return null;
}
}).when(execution).setVariable(anyString(), any());
;
/*
* Stub a DelegateExecution.getVariable() call
*/
when(execution.getVariable(anyString())).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) {
return (String) variableMap.get(invocation.getArguments()[0]);
}
});
/*
* Start the test by invoking the method on execution listener
*/
processEndExecutionListener.notify(execution);
//sample assertion to make sure that the java code is setting correct value
/*
* sample assertion to make sure that the java code is setting correct
* value
*/
assertThat(execution.getVariable("oddOrEven")).isNotNull().isIn("ODD", "EVEN");
}
......
......@@ -3,7 +3,6 @@ package com.alfresco.aps.example.listeners;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.junit.Before;
import org.junit.Test;
......@@ -19,54 +18,77 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class TaskAssignedTaskListenerTest {
@Configuration
static class ContextConfiguration {
@Bean
public TaskAssignedTaskListener taskAssignedTaskListener() {
return new TaskAssignedTaskListener();
}
}
static class ContextConfiguration {
@Bean
public TaskAssignedTaskListener taskAssignedTaskListener() {
return new TaskAssignedTaskListener();
}
}
@InjectMocks
@Spy
private static TaskAssignedTaskListener taskAssignedTaskListener;
@Mock
private DelegateTask task;
@Before
public void initMocks(){
MockitoAnnotations.initMocks(this);
public void initMocks() {
MockitoAnnotations.initMocks(this);
}
/*
* Testing TaskAssignedTaskListener.notify(DelegateTask task) method using a
* mock DelegateTask created using Mockito library
*/
@Test
public void test() throws Exception {
/*
* Creating a map which will be used during the
* DelegateTask.getVariable() & DelegateTask.setVariable() calls from
* TaskAssignedTaskListener as well as from this test
*/
Map<String, Object> variableMap = new HashMap<String, Object>();
/*
* Stub a DelegateTask.setVariable() call
*/
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arg = invocation.getArguments();
variableMap.put((String) arg[0], arg[1]);
return null;
}
}).when(task).setVariable(anyString(), any());;
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arg = invocation.getArguments();
variableMap.put((String) arg[0], arg[1]);
return null;
}
}).when(task).setVariable(anyString(), any());
/*
* Stub a DelegateTask.getVariable() call
*/
when(task.getVariable(anyString())).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) {
return (String) variableMap.get(invocation.getArguments()[0]);
}
});
/*
* Start the test by invoking the method on task listener
*/
taskAssignedTaskListener.notify(task);
when(task.getVariable(anyString())).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) {
return (String) variableMap.get(invocation.getArguments()[0]);
}
});
taskAssignedTaskListener.notify(task);
//sample assertion to make sure that the java code is setting correct value
/*
* sample assertion to make sure that the java code is setting correct
* value
*/
assertThat(task.getVariable("oddOrEven")).isNotNull().isIn("ODDDATE", "EVENDATE");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment