2

I am using the ApexMocks framework and I am having the following error message:

Class.MockTest.testBehavior: line 13, column 1 11:53:56.3 (10709808)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Anyone with experience with the ApexMocks framework that can tell me why the test is failing?

Class to test:

public class fflib_MyList implements IList {
    List<String> myList;

    public fflib_MyList() {
        this(new List<String>());
    }

    private fflib_MyList(List<String> myList) {
        this.myList = myList;
    }

    public void add(String value) {
        myList.add(value);
    }

    public String get(Integer index) {
        return myList.get(index);
    }

    public void clear() {
        myList.clear();
    }

    public Boolean isEmpty() {
        return myList.isEmpty();
    }

    public interface IList {
        void add(String value);
        String get(Integer index);
        void clear();
        Boolean isEmpty();
    }
}

ApexMocks test:

@IsTest
private class MockTest {
    static testMethod void testBehavior() {
        // Given
        fflib_ApexMocks mocks = new fflib_ApexMocks();
        fflib_MyList.IList mockList = (fflib_MyList.IList)mocks.mock(fflib_MyList.class);

        // When
        mockList.add('bob');

        // Then
        ((fflib_MyList.IList) mocks.verify(mockList)).add('bob');
        ((fflib_MyList.IList) mocks.verify(mockList, fflib_ApexMocks.NEVER)).clear();
    }
}

Source : FinancialForce ApexMocks Framework

1 Answer 1

1

I've seen reports recently that Test.createStub() started returning null. Assuming the ApexMocks framework uses that method, which it almost certainly does, then that could explain the null pointer exceptions.

Any1 having issues executing Test.createStub(Type,Object) today? Started seeing it return null an hour ago #askforce @SalesforceDevs

Source

Related Github Issue - fflib_InvocationOnMock is failing

Related Known Issue - System.Test.CreateStub method returns NULL in Apex Tests

2
  • ApexMocks framework uses Stub API :( Commented Aug 8, 2017 at 20:27
  • 1
    On the plus side, from the Known Issue it sounds like the patch is already mostly deployed. Commented Aug 8, 2017 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .