I’m new to JMock, trying to develop a Spring controller test. Here is my test method:
@Test
public void testList() {
context.checking(new Expectations() {{
Student student = new Student(767001);
oneOf(studentService).getByNumber(767001); will(returnValue(student));
}});
ModelMap model = new ModelMap();
Student student = new Student(767001);
model.addAttribute("student", student);
CourseRightController instance = new CourseRightController();
request.setMethod("GET");
Assert.assertEquals(studentService.getByNumber(767001),model.get(student));
The question is how I’m able to test if the model contains the right object and object values? ModelMap is not that flexible than e.g ModelAndWiew. I can’t get access to model attributes so the last code line here is not how it should be.
I usually use the
Modelinterface and then in a test super class I have code which allows me to get at things in the Modelthen in a test I can do
assertEquals("someValue", getModelValue("bean", String.class));or
assertTrue(getModelValue("student", Student.class).getId() == "767001");Note this is all just shorthand for code like this