Unit Testing a static method in a Java Class from Groovy Test case

后端 未结 1 917
余生分开走
余生分开走 2021-01-16 07:55

I am trying to write a test case in groovy for a class that is written in java. The Java class(name:Helper) has a static method in it where a HttpClient object is obtained a

相关标签:
1条回答
  • 2021-01-16 08:13

    You can use

    HttpClient.metaClass.executeMethod = {Type name -> doSomething}
    

    You need to declare the closure signature with the correct Type i.e. String, Map, etc.

    void testSendMessage(){
        def serviceUrl = properties.getProperty("ITEM").toString()
    
        // mocking to return null   
        HttpClient.metaClass.executeMethod = {HttpMethod str -> null}
        def responseXml = helper.message(serviceUrl)
    
    }
    
    0 讨论(0)
提交回复
热议问题