-1
public with sharing class DisplayAttachAccountController {



    private String parentId {
        set;
        get;
    }
    public List < Attachment > attList {
        get;
        set;
    }

    public DisplayAttachAccountController(ApexPages.StandardController stdController) {
        this.parentId = stdController.getId();
        System.debug('&&&&' + parentId);
        attList = [SELECT ParentId, Name, Id, ContentType, BodyLength FROM Attachment
            WHERE ParentId in (Select Id from opportunity where accountId =: this.ParentId)
        ];
    }

}

@isTest
public class AttachTesting {
    static testmethod void validateAttach(){
        Account obj = new Account(Name ='Test');
         insert obj;

        //apexpages.currentpage().getparameters().put('id' , yourID);

        ApexPages.StandardController stdController;
      DisplayProfilePictureController conAttach= new DisplayProfilePictureController(stdController);  

    }
}

2 Answers 2

0

Hope this helps..

public class AttachTesting

{

     static testmethod void validateAttach()  
    {

        Account obj = new Account(Name ='Test');
         insert obj;

        Attachment att=new Attachment();
        att.Body=Blob.valueOf('test');
        att.Name='test';
        att.ParentId=obj.Id;
        insert att;
        //apexpages.currentpage().getparameters().put('id' , yourID);

        ApexPages.StandardController stdController=new  ApexPages.StandardController(att); 
       DisplayProfilePictureController conAttach= new DisplayProfilePictureController (stdController);  

    }
}
1

Please find the below to cover the above class. You just need to create an instance of Standard controller and pass that to the constructor.

@isTest
public class AttachTesting {
    static testmethod void validateAttach(){
        Account obj = new Account(Name ='Test');
        insert obj;
        Attachment attach=new Attachment(Body = Blob.valueOf('Unit Test Attachment Body'), Name='Unit Test Attachment', parentId=obj.Id);       
        insert attach;

        ApexPages.StandardController stdController = new ApexPages.StandardController(obj);
        DisplayProfilePictureController conAttach= new DisplayProfilePictureController(stdController);  
    }
}

Not the answer you're looking for? Browse other questions tagged .