• IGate
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies

Help me, to write the test class for below class.

 

 

public with sharing class AttachmentUploadController {
    public String FrameDisplay { get; set; }
    public String Imagesrc { get; set; }
 // Get & Set properties of an Attachment.
  public Attachment attachment {
  get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
  set;
  }
 // Getting Current Id of an Account & Inserting Attached file to an attachment object.
  public pagereference upload() {
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = ApexPages.CurrentPage().getParameters().get('Id'); // the record the file is attached to
    attachment.IsPrivate = true;
 
    try {
      insert attachment;
      Imagesrc='https://' +ApexPages.Currentpage().getHeaders().get('Host')+ '/servlet/servlet.FileDownload?file=' + attachment.Id;
    }
    catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      return null;
    } finally {
      attachment = new Attachment();
    }
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
    return null;
  }

static testmethod void testm1()
{
    AttachmentUploadController obj=new AttachmentUploadController ();
    obj.upload();
}
}

 

The red marked lines are not covering in my class. How can i cover those red marked lines.

  • July 19, 2011
  • Like
  • 0

public class abcd
     {
      public void m1()
      {
      Attachment myAttach = new Attachment();
      myAttach.ParentId = '001900000063kAB';//Id of the object to which the page is attached
      myAttach.name = 'attachment';
      PageReference myPdf = Page.one;//myPdfPage is the name of your pdf page
      myAttach.body = myPdf.getContentAsPdf();
      insert myattach;  
      }
      
      static testmethod void testm1()
      {
          abcd obj1=new abcd();
          obj1.m1();
      }
     }

 

Hi how can i conver the red marked line.



  • July 19, 2011
  • Like
  • 0

I have a class like this:

How can i write test class for this.

Please hellp me.

 

public class aaPage78 {
 public List<selectList> lists {get; set;}
 public aaPage78() {
  lists = new List<selectList>();
  for (Integer i = 0; i < 5; i++) {
   lists.add(new selectList(i));
  }
 }
 public PageReference test() {
  return null;
 }
 public class selectList {
  Integer intValue;
  String[] countries = new String[]{};
  public selectList(Integer intValue) {
   this.intValue = intValue;
  }
  public List<SelectOption> getItems() {
   List<SelectOption> options = new List<SelectOption>();
   options.add(new SelectOption('Value:' + intValue + ' - US','Label:' + intValue + ' - US'));
   options.add(new SelectOption('Value:' + intValue + ' - CANADA','Label:' + intValue + ' - Canada'));
   options.add(new SelectOption('Value:' + intValue + ' - MEXICO','Label:' + intValue + ' - Mexico'));
   return options;
  }
  public String[] getCountries() {
   return countries;
  }
  public void setCountries(String[] countries) {
   this.countries = countries;
  }
 }
}

 

 

Test Class:

 

I wrote the following test class to cover the above class.

But it gives only 52% code coverage. The red marked code did not cover.

 

@istest
private class testaapage78
{
    public static testmethod void m1()
    {
        aaPage78 obj=new aaPage78();
        obj.test();
    }
}

 

 

Can any one help me to covert the red marked code.

 

  • July 19, 2011
  • Like
  • 0

public class abcd
     {
      public void m1()
      {
      Attachment myAttach = new Attachment();
      myAttach.ParentId = '001900000063kAB';//Id of the object to which the page is attached
      myAttach.name = 'attachment';
      PageReference myPdf = Page.one;//myPdfPage is the name of your pdf page
      myAttach.body = myPdf.getContentAsPdf();
      insert myattach;  
      }
      
      static testmethod void testm1()
      {
          abcd obj1=new abcd();
          obj1.m1();
      }
     }

 

Hi how can i conver the red marked line.



  • July 19, 2011
  • Like
  • 0

I have a class like this:

How can i write test class for this.

Please hellp me.

 

public class aaPage78 {
 public List<selectList> lists {get; set;}
 public aaPage78() {
  lists = new List<selectList>();
  for (Integer i = 0; i < 5; i++) {
   lists.add(new selectList(i));
  }
 }
 public PageReference test() {
  return null;
 }
 public class selectList {
  Integer intValue;
  String[] countries = new String[]{};
  public selectList(Integer intValue) {
   this.intValue = intValue;
  }
  public List<SelectOption> getItems() {
   List<SelectOption> options = new List<SelectOption>();
   options.add(new SelectOption('Value:' + intValue + ' - US','Label:' + intValue + ' - US'));
   options.add(new SelectOption('Value:' + intValue + ' - CANADA','Label:' + intValue + ' - Canada'));
   options.add(new SelectOption('Value:' + intValue + ' - MEXICO','Label:' + intValue + ' - Mexico'));
   return options;
  }
  public String[] getCountries() {
   return countries;
  }
  public void setCountries(String[] countries) {
   this.countries = countries;
  }
 }
}

 

 

Test Class:

 

I wrote the following test class to cover the above class.

But it gives only 52% code coverage. The red marked code did not cover.

 

@istest
private class testaapage78
{
    public static testmethod void m1()
    {
        aaPage78 obj=new aaPage78();
        obj.test();
    }
}

 

 

Can any one help me to covert the red marked code.

 

  • July 19, 2011
  • Like
  • 0