Pruebas Unitarias

Ejemplo de prueba:

@Test
void testListarCursos() throws Exception {
    CursoDTO curso = new CursoDTO();
    curso.setId("JAV1234");
    curso.setNombre("Java");
    curso.setEstadoNombre("Disponible");

    when(cursoService.getCursos()).thenReturn(List.of(curso));

    mockMvc.perform(get("/api/cursos"))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$[0].nombre", is("Java")));
}

@Test
void testBuscarCursoFound() throws Exception {
    CursoDTO curso = new CursoDTO();
    curso.setId("JAV1234");
    curso.setNombre("Java");

    when(cursoService.getCursoById("JAV1234")).thenReturn(curso);

    mockMvc.perform(get("/api/cursos/JAV1234"))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.nombre", is("Java")));
}

Last updated