-1

I am writing a Junit test case using Mockito & PowerMockito in Java. Below are the code snippet:

ApplicationCovrgeCommonRules class has method checkForValidFormIdForCoverageTest() which needs to be tested. This method is calling another method (of same class) getCarirSysID() having return type String.

@Test
public void checkForValidFormIdForCoverageTest() throws Exception{
            String caseId="caseId";
            StateVO stateVO = new StateVO(); stateVO.setDeliveryState("AK");
            Mockito.when(dsBean.getStateInfo(any())).thenReturn(stateVO);
            String carirSysID="CarirSysID"; 
            ApplicationCovrgeCommonRules applicationCovrgeCommonRulesMock= 
           Mockito.spy(applicationCovrgeCommonRules);
         Mockito.doReturn(carirSysID).when(applicationCovrgeCommonRulesMock).getCarirSysID(caseId);

applicationCovrgeCommonRules is defined as:

@InjectMocks
ApplicationCovrgeCommonRules applicationCovrgeCommonRules;

While running this code, I am getting error as

> unnecessary Mockito stubbings FAILED
    org.mockito.exceptions.misusing.UnnecessaryStubbingException
Raushan
  • 214
  • 2
  • 3
  • 10

1 Answers1

-1

UnnecessaryStubbingException indicates presence of unused stubbings. Removing unused stubbings will fix the issue. Reference: https://www.javadoc.io/doc/org.mockito/mockito-core/2.6.5/org/mockito/exceptions/misusing/UnnecessaryStubbingException.html

Veena
  • 1
  • 1