• gb__
  • NEWBIE
  • 10 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hi all,

I'm struggling to get code coverage on my class.  I've never written a test class for a Controller, only triggers, so I'm a bit lost.
Any help would be greatly appreciated.
 

Thanks,

Greg

Class

public with sharing class ShowAttachments_Controller {
private List<Id> photoIds;
private ApexPages.standardController controller;
private List<Id> chatterphotoIds;
private Acquisition_Report__c acquisition;
public ShowAttachments_Controller(ApexPages.StandardController controller) { 
this.controller = controller;         
 this.acquisition = (Acquisition_Report__c)controller.getRecord();
}

public List<Id> photosfromchatter {
get {
if(chatterphotoIds == null) {
chatterphotoIds = new List<Id>();
for(ContentVersion cnt : [select Id from ContentVersion ]) {
chatterphotoIds.Add(cnt.Id);
}
}

return chatterphotoIds;
}
} 

public List<Id> photos {
        get {
            if(photoIds == null) {
                photoIds = new List<Id>();
                for(Attachment att : [select Id from Attachment where ParentId = :acquisition.Id]) {
                    photoIds.Add(att.Id);
                }
            }
                             
            return photoIds;
        }
    }
     
    public Integer totalPhotos {
        get {
            return photos.size();
        }
    }

}

Test Class
@isTest
private class ShowAttachments_ControllerTest {
     
    static testMethod void validateShowAttachments_ControllerTest(){
   
{
        Account acc=new Account(Name='Acme Inc');
        insert acc;
       test.startTest();
        Attachment attach=new Attachment();   	
    	attach.Name='Unit Test Attachment';
    	Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    	attach.body=bodyBlob;
        attach.parentId=acc.id;
        insert attach;
    	
        
        List<Attachment> attachments=[select id, name from Attachment where parent.id=:acc.id];
        System.assertEquals(1, attachments.size());
    	String myString = 'StringToBlob';
		Blob myBlob = Blob.valueof(myString);
		System.assertEquals('StringToBlob', myBlob.toString());
    }
        test.stopTest();
}        
}

 
  • February 08, 2015
  • Like
  • 0

I am currently in the process of searching for a developer who can build assist with developing a management system for our use on the force.com platform.

 

High level requirements:

API access to estimating systems to import and sync data from the point of origin.

Import estimate line items in to the record.

The ability to indicate parts as on order, received, returned, back ordered, etc.

Job costing and calculation validation.

 

More details to follow. 

Preferably located in the northeast for ease of travel when needed.

 

Please let me know if you're interested and we can discuss in more detail.

 

Thanks,


Greg

 

  • March 16, 2012
  • Like
  • 0

Hi all,

I'm struggling to get code coverage on my class.  I've never written a test class for a Controller, only triggers, so I'm a bit lost.
Any help would be greatly appreciated.
 

Thanks,

Greg

Class

public with sharing class ShowAttachments_Controller {
private List<Id> photoIds;
private ApexPages.standardController controller;
private List<Id> chatterphotoIds;
private Acquisition_Report__c acquisition;
public ShowAttachments_Controller(ApexPages.StandardController controller) { 
this.controller = controller;         
 this.acquisition = (Acquisition_Report__c)controller.getRecord();
}

public List<Id> photosfromchatter {
get {
if(chatterphotoIds == null) {
chatterphotoIds = new List<Id>();
for(ContentVersion cnt : [select Id from ContentVersion ]) {
chatterphotoIds.Add(cnt.Id);
}
}

return chatterphotoIds;
}
} 

public List<Id> photos {
        get {
            if(photoIds == null) {
                photoIds = new List<Id>();
                for(Attachment att : [select Id from Attachment where ParentId = :acquisition.Id]) {
                    photoIds.Add(att.Id);
                }
            }
                             
            return photoIds;
        }
    }
     
    public Integer totalPhotos {
        get {
            return photos.size();
        }
    }

}

Test Class
@isTest
private class ShowAttachments_ControllerTest {
     
    static testMethod void validateShowAttachments_ControllerTest(){
   
{
        Account acc=new Account(Name='Acme Inc');
        insert acc;
       test.startTest();
        Attachment attach=new Attachment();   	
    	attach.Name='Unit Test Attachment';
    	Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    	attach.body=bodyBlob;
        attach.parentId=acc.id;
        insert attach;
    	
        
        List<Attachment> attachments=[select id, name from Attachment where parent.id=:acc.id];
        System.assertEquals(1, attachments.size());
    	String myString = 'StringToBlob';
		Blob myBlob = Blob.valueof(myString);
		System.assertEquals('StringToBlob', myBlob.toString());
    }
        test.stopTest();
}        
}

 
  • February 08, 2015
  • Like
  • 0