Code Monkey home page Code Monkey logo

Comments (4)

stohn777 avatar stohn777 commented on September 22, 2024 1

Hi @gesta22. Like you've done for the mockCaseSelector, you must mock that sObjectType() method for the Domains, enabling the factory to register the classes for the corresponding SObjectType.

Also as an observational note, the best practice for creating a mock is using the related Interface as opposed to the concrete class, although it works. The reasoning is ensuring that the interfaces match the classes. By mocking the concrete class it's possible the existence of an undocumented, in the interface, method could slip through testing. For instance, a developer might have added xyzMethod(...) to the class but forgot to add it to the interface, which would not be detected when testing with a mock of the concrete class.

An interpretation of the Issue's code using the interfaces.

fflib_ApexMocks mocks = new fflib_ApexMocks();
IBPP_CaseSelector mockCaseSelector = (IBPP_CaseSelector)mocks.mock(IBPP_CaseSelector.class);
IBPP_Cases mockCaseDomain = (IBPP_Cases)mocks.mock(IBPP_Cases.class);
IBPP_CaseEntityAssociations mockCaseEntityDomain = (IBPP_CaseEntityAssociations)mocks.mock(IBPP_CaseEntityAssociations.class);

from fflib-apex-mocks.

gesta22 avatar gesta22 commented on September 22, 2024

If anyone interested, it got resolved after I stubbed this method for all domains:
mocks.when(mockDomain.sObjectType()).thenReturn(MyObject__c.SObjectType);

from fflib-apex-mocks.

gesta22 avatar gesta22 commented on September 22, 2024

@stohn777 Not sure I'm getting your point on interfaces. Class don't have to be related to just 1 interface. What if my domain class implements several interfaces?

from fflib-apex-mocks.

stohn777 avatar stohn777 commented on September 22, 2024

@gesta22
Initially this thread was talking about Selectors, and the typical pattern is creating an interface for the selector that extends fflib_SObjectSelector. In the snippets of your code, you would have an IBPP_CaseSelector Interface. This is the what would be registered with the Application.Selector factory. It's true that the selector might implement other interfaces, but this would be the one that's relevant to the factory pattern.

Domains would generally exhibit the same pattern. The relevant interface would be the one extending fflib_ISObjectDomain and would be used to configure the pattern or leveraged when creating mocks.

I hope that provides a bit of clarification.

from fflib-apex-mocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.