codeMan
codeMan

Reputation: 5758

How to partially mock 'equalsIgnoreCase' method of java.lang.String

I am using Mockito/Power Mockito for unit testing. I want to mock the method 'equalsIgnoreCase' in java.lang.String class.

Other methods of java.lang.String should behave as it is, I want to mock only 'equalsIgnoreCase' method.

Could anyone please give an example for this ?

Upvotes: 1

Views: 943

Answers (1)

parsifal
parsifal

Reputation: 299

Rewrite your while condition so that it calls a method. This benefits you in several ways:

  1. It's easy to mock
  2. It won't throw an exception if str1 is null.
  3. It documents exactly what the loop is trying to accomplish.

Upvotes: 3

Related Questions