vendredi 1 avril 2016

Mocking static private final variable using Powermock?

I have a utility class which is a final class. There i have used injection for injecting LOGGER.

public final class Utility {

    @Inject
    private static Logger.ALogger LOGGER;

    private CcpProcessorUtilities() {
       //this is the default constructor. so there is no implementation
    }

    public static String convertToURl(string input){
       try{
             //do some job
          }catch(IllegalArgumentException ex){
             LOGGER.error("Invalid Format", ex);
          }
   }

}

While I writing unit testing for this method i have to mock LOGGER otherwise it will throw null pointer exception. How can i mock this LOGGER without creating instance of this class. I tried to whitebox the variable. But it only works with instances?

Aucun commentaire:

Enregistrer un commentaire