I am trying to mock a class with a method that has 3 arguments, and these 3 arguments could be any of its own types. I used the fflib_ApexMocks to return 'hello world' whenever the method is called; however, fflib_ApexMocks is returning null instead. I tried the following:
fflib_ApexMocks mocks = new fflib_ApexMocks();
ClassB classBMock = (ClassB) mocks.mock(ClassB .class);
mocks.startStubbing();
mocks.when(classBMock.doBStuff((Class3) fflib_Match.anyObject(), (DummyEnum) fflib_Match.anyObject(), fflib_Match.anyString())).thenReturn('Hello world');
ClassA = classA = new ClassA(classBMock);
mocks.stopStubbing();
As follows code example:
class classA {
private ClassB classB;
public classA(ClassB classB) {
this.classB = classB;
}
public void doAStuff() {
// ....
String result = classB.doBStuff(new ClassC(), DummyEnum.PIGGY, 'Hi man');
// ....
}
}
class ClassB {
public String doBStuff(ClassC classC, DummyEnum dummyEnum, String message) {
// ...
return 'bla';
}
}
class ClassC {
}
public enum DummyEnum {
DOG,
KOALA,
PIGGY
}