7

I have been using the Salesforce Security Scanner to scan my code:

http://security.force.com/security/tools/forcecom/scanner

Basically, the scan is telling me that I do not have any assert statements in my test class. It does not make any sense because I have several... and have even added in some pointless ones for further testing. Does anyone know why it might be showing up on the scanner?

@isTest
private class InactiveSalesRepControllerTest
{
    static testMethod void testInactiveLeadReassignment()
    {
        User u = [SELECT Id FROM User WHERE Department = 'Sales' AND UserRole.Name IN :Constants.REP_ROLES AND CompanyName = 'Equity Trust' AND IsActive = true AND Id != :UserInfo.getUserId() LIMIT 2][1];
        List<Lead> testLeads = new List<Lead>();
        System.RunAs(new User(Id = UserInfo.getUserId()))
        {
            for(Integer i = 0; i < 3; i++)
            {
                Lead l = new Lead(FirstName = 'Test', LastName = 'Test', OwnerId = u.Id);
                testLeads.add(l);
            }
            testLeads[2].Status = Constants.DORMANT_STATUS;
            insert testLeads;
            //testLeads[2].OwnerId = u.Id;
            //update testLeads[2];

            Task t = new Task(OwnerId = u.Id, Status = 'New', Subject = 'Test', WhoId = testLeads[0].Id);
            insert t;
        }

        u.IsActive = false;
        update u;

        Test.startTest();
        InactiveSalesRepController testMe = new InactiveSalesRepController();
        System.RunAs(new User(id = UserInfo.getUserId()))
        {
            testMe.findLeads();
            testMe.activeLeadsWithTasksReassign = 1;
            testMe.activeLeadsWithoutTasksReassign = 1;
            testMe.dormantLeadsReassign = 1;
            testMe.selectedActiveRep = testMe.activeSalesReps[0].getValue();
            testMe.assignLeads();
        }
        System.assert(true);
        Test.stopTest();

        //Had to remove the dormant parts because it is causing issues in production when we update the user after
        //updating the Lead (Mixed DML)
        List<Lead> leads = [SELECT OwnerId FROM Lead WHERE Id IN :testLeads AND Status != :Constants.DORMANT_STATUS];
        for (Lead tLead: leads)
        {
            System.assertEquals(testMe.selectedActiveRep, tLead.OwnerId);
        }
        System.assert(2 == leads.size());

        //For some reason the security scanner kept saying that there were no asserts even though there are 2 above this... so I added this
        //to try to fix it.
        System.assert(true);
    }
}

2 Answers 2

3

I cannot see anything particularly wrong with your code above, your using a number of variations of System.assert vs System.assertEquals as well, so it's not as if it may favour one over the other for some reason. So all i can say is contact them via the Email contact option here.

4
  • 1
    Good plan. Idk why I never think of contacting the companies directly...
    – dphil
    Apr 14, 2014 at 15:17
  • Well... Update on this. Contacting the company directly, and I never got a response. There is actually an email division in Salesforce you can email directly about this sort of thing. I got a single response directly back from them... that wasn't even close to answering my question. It was a response that was given blaming System.assert(true). Basically ignoring the fact that I only added those in after it was already getting this issue with the valid asserts.
    – dphil
    Apr 28, 2014 at 15:15
  • Sigh, not good, and sadly something i have also experienced all to often. I would recommend raising a Salesforce case and contacting your account manager (or Technical Account Manager if you have one). Apr 29, 2014 at 10:12
  • @dphil, Sorry that you did not feel you got adequate help via email. In that case, please book an office hour for live online help: security.force.com/security/contact/ohours Feb 3, 2015 at 1:16
3

I found the culprit on my own. I noticed that the System.RunAs(new User(Id = UserInfo.getUserId())) the previous developer used essentially does nothing at all. I removed that as well as put asserts inside of the other System.runAs and outside of it as well, and it began working as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.