-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed
Labels
type: enhancementA general enhancementA general enhancement
Milestone
Description
spring-boot version is 2.1.3.RELEASE
I already addressed the issue in mockito. issue
the mockito 3.4.0 can mock static method, so I upgrade mockito to 3.4.0, but the mock framework changed, now when I use
the @SpyBean and then verify it. it will throw NotAMockException.
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
@AutoConfigureMockMvc
public class AppGroupClusterActionTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private AppGroupClusterService appGroupClusterService;
@SpyBean
private AppGroupClusterAction appGroupClusterAction;
@Captor
private ArgumentCaptor<Object[]> argumentCaptor;
@Test
public void testUpdateExecuteAuditSpel() throws Exception {
ServiceResult mockRes = new ServiceResult();
mockRes.setSuccess(true);
doReturn(mockRes).when(appGroupClusterService).update(
Mockito.any(), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any(), Mockito.any());
mockMvc.perform(
MockMvcRequestBuilders.post("/platforms/{platform}/appGroupNames/{appGroupName}/clusterNames/{clusterName}/update",
"platform", "appGroupName", "clusterName").content("{}"))
.andExpect(status().isOk())
.andReturn();
// not work
// verify(appGroupClusterAction).addAfterAuditResult(argumentCaptor.capture());
verify((AppGroupClusterAction) AopTestUtils.getTargetObject(appGroupClusterAction)).addAfterAuditResult(argumentCaptor.capture());
assertArrayEquals(argumentCaptor.getValue(), new Object[]{"appGroupName", "platform", "clusterName", "{}"});
verify((AppGroupClusterAction) AopTestUtils.getTargetObject(appGroupClusterAction)).addAfterAuditResult(argumentCaptor.capture());
assertArrayEquals(argumentCaptor.getValue(), new Object[]{"appGroupName", "platform", "clusterName", "{}"});
}
}
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement