Issues in writing test case using PowerMock

140 views Asked by At

I am trying to write a test case for checkRegistry method, which is a private method, I am using PowerMock-EasyMock-Juint to realize this.

Now to test this methods I want to suppress the calls to super calls methods eg:

intigration = super.getParam("integritycheck"); 

I dont want the call to go to superClass method, but at the same time I want the variable integration to be set. How do I realize this?

The difficulty is

super.getParam("integritycheck");  and 
        sTmpOverride = super.getParam("RESPONSE_OVERRIDE"); will return different results. 

Method that I am trying to write unit test.

private String checkRegistry()
      {
        String intigration = "";
        String sresponse = "";
        try
        {
          try
          {
            intigration = super.getParam("integritycheck");
            sresponse = CustomImpl.getParam("responseWrite");


            **Some Business Logic** 


        sTmpOverride = super.getParam("RESPONSE_OVERRIDE");
        if (sTmpOverride == null) {
            this._bRespOverride = true;
        } else {
            this._bRespOverride = sTmpOverride.trim().equalsIgnoreCase(
                    "true");
        }


        sTmpOverride = super.getParam("ERROR_OVERRIDE");
        if (sTmpOverride == null) {
            this._bErrOverride = true;
        } else {
            this._bErrOverride = sTmpOverride.trim().equalsIgnoreCase(
                    "true");
        }

                    **Some Business Logic** 


          Logging.info("integritycheck  : " + intigration );
          Logging.info("responseWrite   : " + sresponse );
          super.track("Error Directory    : " + sErrorPath);
          }
        }
        catch (Exception ex)
        {
          _result= false;
        }
        return _result;
      }

I am struck on using the below method

 suppress(method(CustomRegisterChecker.class, "getParam"));

where CustomRegisterChecker.class is the super class.

UPDATE1:

//Here I am creating a mock for the super class
 CustomRegisterChecker customRegisterMock=createMock(AbstractListener.class);

//I am supresssing the calls made to the super class and giving my own response

    expect(abstractListenerMock.getParam("integritycheck  ")).andReturn(null);
    expect(abstractListenerMock.getParam("responseWrite")).andReturn(null); 

But How do I invoke and test the method. I tried using Reflection API. BUT that does not work. it just simply run the program, supressing the super class methods does not happen here.

0

There are 0 answers