Junit test case getting failed:
existing static mocking registration must be deregistered
Test class:
@RunWith(MockitoJUnitRunner.class)
public class DeleteReportServiceTest {
@InjectMocks
private ReturnCheckController returnCheckController;
@Mock
MockedStatic<DigitalGatewayRESTClient> mockDigiGateway;
@Before
public void setUp() throws Exception {
this.returnCheckController = new ReturnCheckController();
this.mockDigiGateway = Mockito.mockStatic(DigitalGatewayRESTClient.class);
}
@Test
public void testdeleteReport() throws Exception {
String input = "{\"clientId\": \"1\", \"applicationId\": \"9010\"}";
String response = "{\"success\":true,\"successText\":\"Manual adjustment record deleted\"}";
String expected = "{\"status\":200}";
JSONObject returnJson = new JSONObject(response);
mockDigiGateway.when((Verification) DigitalGatewayRESTClient.getDGRESTConnection(Mockito.any())).thenReturn(returnJson);
String actual = returnCheckController.deleteReport(input);
Assert.assertNotNull(actual);
Assert.assertEquals(expected, actual);
}
@After
public void after() {
mockDigiGateway.close();
}
}
Closing the static mocking still am getting the error.