apex-enterprise-patterns / fflib-apex-mocks

An Apex mocking framework for true unit testing in Salesforce, with Stub API support
BSD 3-Clause "New" or "Revised" License
423 stars 214 forks source link

Improper mock class generated when extends on separate line #54

Closed john-storey closed 4 years ago

john-storey commented 7 years ago

If an interface contains and extends clause and the clause is on a different line from the interface name, the generated mock class is poorly formed.

Below are a couple examples. Given the different placement of the extends clause, the generated class should be well formed and logically identical.

Given the following interface, having the extends clause on the same line as the interface name.

public interface ICronTriggersSelector extends ISObjectSelector
{
    List<CronTrigger> selectById(Set<Id> idSet);
}

The proper mock class is generated.

/* Generated by apex-mocks-generator version 4.0.1 */
@isTest
public class MockClasses
{
    public class CronTriggersSelectorMock extends ISObjectSelector implements ICronTriggersSelector
    {
        private fflib_ApexMocks mocks;

        public CronTriggersSelectorMock(fflib_ApexMocks mocks)
        {
            super(mocks);
            this.mocks = mocks;
        }

        public List<CronTrigger> selectById(Set<Id> idSet)
        {
            return (List<CronTrigger>) mocks.mockNonVoidMethod(this, 'selectById', new List<Type> {System.Type.forName('Set<Id>')}, new List<Object> {idSet});
        }
    }
}

But when the interface's extends clause is moved to the following line.

public interface ICronTriggersSelector
    extends ISObjectSelector
{
    List<CronTrigger> selectById(Set<Id> idSet);
}

Notice the improper code that appears after the mock class's constructor.

/* Generated by apex-mocks-generator version 4.0.1 */
@isTest
public class MockClasses
{
    public class CronTriggersSelectorMock extends ISObjectSelector implements ICronTriggersSelector
    {
        private fflib_ApexMocks mocks;

        public CronTriggersSelectorMock(fflib_ApexMocks mocks)
        {
            super(mocks);
            this.mocks = mocks;
        }

        public extends ISObjectSelector{    List<CronTrigger> selectById(Set<Id> idSet)
        {
            return (extends ISObjectSelector{    List<CronTrigger>) mocks.mockNonVoidMethod(this, 'selectById', new List<Type> {System.Type.forName('Set<Id>')}, new List<Object> {idSet});
        }
    }
}
ImJohnMDaniel commented 7 years ago

@afawcett, @dfruddffdc, @phardakerffdc -- I believe this is the same issue seen in #4. It has all of the same symptoms as that issue did back then.

XoNoXForce commented 7 years ago

I have a fix for that, it's on internal code review

afawcett commented 4 years ago

Merged https://github.com/apex-enterprise-patterns/fflib-apex-mocks/pull/57