samedi 7 février 2015

How can test Spring component with JMock?

I've used Mockito to test my code but at present I want to migrate to JMock. I don't know how I can use JMock to refer to my spring beans. In Mockito I defined same as bellow and it works well:



public class MyClassTest extends AbstractSpringAwareJerseyTest {
@Autowired
private TaskManager taskManager;

@Override
public AppDescriptor configure() {
// Pickup the resources.
// Need to inject the spring context
// See ResourceConfig for init params.
WebAppDescriptor wa = new WebAppDescriptor.Builder("mo.task,mo.base,builders,core.utils.util,org.codehaus.jackson.jaxrs")
.contextPath("/")
.contextParam("contextConfigLocation", "classpath:test-spring.xml")
.contextListenerClass(ContextLoaderListener.class)
.servletClass(SpringServlet.class)
.build();
return wa;
}
@Test
public void myTest() {
Mockito.when(taskManager.get(Mockito.anyLong())).thenReturn(task);

//This web service uses taskManager.get() internally
ClientResponse response = resource().path("/task/taskPaste2/1/57/-1/null/true").post();
}
}


and in my test-spring.xml:



<bean id="taskManager"
class="MockitoFactoryBean">
<constructor-arg>
<value type="java.lang.Class">mo.task.TaskManagerImpl</value>
</constructor-arg>
</bean>


Now I am goring to use JMock instead of Mockito. How can I do this?


Aucun commentaire:

Enregistrer un commentaire