'java.lang.AssertionError: Status expected<200> but was <500>

I am getting this erorr while writing test case for controller method. I know status should be ok but getting InternalserverError. Don't know where I am doing mistake. Error Maybe because of I am passing Project entity in pathvariable and writing test case for string projectId. I am not sure.

Controller:

@ApiOperation
@GetMapping("/projects/{projectId}/capabilities")
public OEMCapabilitiesDto getProjectOEMCapabilities(@PathVariable("projectId") @NotNull Project project) { 
        return capabilityService.getProjectOEMCapabilities(project); 
    }

Test:

@Test
public void testGetProjectOEMCapabilities() throws Exception {

        OEMCapabilitiesDto oemCapabilitiesDto = new OEMCapabilitiesDto();

        Mockito.when(capabilityService.getProjectOEMCapabilities(Mockito.any(Project.class)))
                .thenReturn(oemCapabilitiesDto);

        RequestBuilder requestBuilder = MockMvcRequestBuilders
                .get("/api/projects/{projectId}/capabilities", "5f35c618548e36161c9be16b")
                .param("projectId", "5f35c618548e36161c9be16b")
                .accept(MediaType.APPLICATION_JSON).content("send all the required data with project");

        MvcResult result = mockMvc.perform(requestBuilder).andExpect(status().isOk()).andReturn();
    
        assertNotNull(result);
    }

I am getting MethodArgumentConversionNotSupportedException in console. Failed to convert value of type 'java.lang.string' to required type ' models.projects.Project'.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source