Reputation: 11
I need to simulate a scenario where my test needs to be returning a particular value for String.length function i.e- String str[]= abc.getValue();
if(String.length != 100){//do this} else {//do that}
I want to mock String length to return 100 so that I can execute else loop
Any suggestions will be appreciated.
Upvotes: 0
Views: 1341
Reputation: 26868
If you are on Java 11 or above, you can use this to create a String of length 100 and avoid the mocking:
String s = "x".repeat(100)
Upvotes: 1