0

I want to mock A.notNull(obj) method in my TestB.java class using EasyMock. I am struggling to mock this method since one week.

//A.class
public class A
{
    public static void notNull(Object o)
    {
       notNull(o,"object is null");
    }
    public static void notNull(Object o, String s)
    { 
       if (o==null)
       {
           throw new IllegalArgumentException(s);   
       }
    }
 }

 //B.class
 Class<? extends E> obj;

 protected final Simple limit()
 {
     A.notNull(obj); //I want to mock this line in my TestB.java class using EasyMock framework
 }

Any help would be appreciated.

1 Answers1

1

Indeed, EasyMock doesn't support mocking static methods. You need to add PowerMock on top of it to do so.

However, in your case, I would indeed not mock notNull. It doesn't do anything that requires mocking. You don't even need this method since Objects.requireNotNull does the same thing.

Henri
  • 5,551
  • 1
  • 22
  • 29