dimanche 30 mars 2014

Junit - Spring - Testing Collections


Vote count:

0




Can you please advise who to test Collection with JUnit 4 and Spring MVC?


Testing a Person class can be done by:



public class TestPersonController {

@Mock
private PersonService personService;

@InjectMocks
private PersonController personController;

private MockMvc mockMvc;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(personController).build();
}

@Test
public void testGetPerson() throws Exception {
when(personService.getPerson(1L)).thenReturn(new Person(1L, "StackOverflow"));

mockMvc.perform(get("/person/{id}", 1L))
.andExpect(status().isOk())
.andExpect(view().name("personPage"))
.andExpect(model().attribute("personData",
allOf(hasProperty("id", is(1L)),
hasProperty("name", is("StackOverflow")))));
}
}


But I am not able to figure out how to test if perService.getPerson return List!



asked 37 secs ago






Aucun commentaire:

Enregistrer un commentaire