java - Jmockit String final length method mocking Issue -


using jmockit 1.2 jar, trying mock string's length method getting unexpected invocation exception:

failed: test java.lang.illegalstateexception: missing invocation mocked type @ point;      please make sure such invocations appear after declaration of suitable mock   field or parameter @ stringdemo.testa$1.<init>(testa.java:17) @ stringdemo.testa.test(testa.java:13) 

i using testng:

@test    public void test() throws exception    {     new expectations()       {         @mocked("length")         string astring;          {             astring.length();             result = 2;          }       };        system.out.println(a.showa("test"));    } } 

actual class a:

public class { public static int showa(string str){     int a= str.length();     return a;  } } 

this wrong way of recording expected results. shouldn't mock , record string's length() method, record showa() instead. here solution

    @suppresswarnings("unused")     @test     public void test() throws exception     {          new expectations()         {             @nonstrict             final source mock = null;              {                 source.showa(anystring);                 result = 2;             }         };          assertequals(2, source.showa("test"));     } 

Comments

Popular posts from this blog

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -