Giter VIP home page Giter VIP logo

at4dx-samplecode's People

Contributors

github-actions[bot] avatar imjohnmdaniel avatar stohn777 avatar tafari-salesforce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

at4dx-samplecode's Issues

How to mock AbstractSelectorMethodInjectable?

Question

How do you mock an AbstractSelectorMethodInjectable where the class is called from another layer (like Service)?

The sample code shows how to do it when making the selectInjection call from the actual test. How do you do it when the selectInjection call is not in the test itself, but rather in the class under test?

For example, this test fails with a NullPointerException - rygramer@bd26854. (This is essentially a copy and paste from the sample code test, except for line 143.)

Answer

If you dont implement the equals method inside of the Parameters class, when you are creating another instance of the Parameters for testing the injection, that is using a memory reference to compare the objects
Those objects are not equal, thus the mock does not meet its criteria, thus it returns nothing, which you assign to your list
Which you then get a NPE because you are trying to access size of a null list
It worked in the sample because the same instance of the SelectBySloganSelectorMethod.Parameters was being used, thus it was equal
(obligatory RTFM reference -> https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_maps_keys_userdefined.htm)
The docs are talking about Maps and Sets, but the overall concept is relevant here
np! For reference, we dont add the equals and hashCode methods for you, since we arent sure what attributes you are going to define for your Parameters

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.