• Durgles
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello.  I'm trying to populate a list with some dummy records so I can do some unit testing.  However, when I do a for loop, the list remains null and the assertion fails.  I've tried two different assignment techniques but neither works.  If I get rid of either for loop and just put in a line j = 0, then the list is populated.  I can't figure out what I'm doing wrong here.

Thanks
David
Code:
public class Util {

 static testmethod void testAllTriggers() {
  Integer i, j;
 
  //Set up a contact and payments for testing.
  Contact person = new Contact(FirstName = 'John', LastName = 'Qwertyuiop');
  insert person;
  Id contactID = [select id from Contact where LastName = 'Qwertyuiop'].Id;
  Membership_Payment__c[] payments = new Membership_Payment__c[23];

//THIS LOOP FAILS TO POPULATE
//  for (j = 0; j == 22; j++) {
//   payments[j] = new Membership_Payment__c(Contact__c = ContactID, Name = (2010 + j).format(),
//    Posted_Date__c = Date.newInstance(2010 + j, 1, 2), Amount__c = 20);
//  }

//THIS LOOP ALSO FAILS TO POPULATE
//  for (j = 0; j == 22; j++) {
//   payments.add(new Membership_Payment__c(Contact__c = ContactID, Name = (2010 + j).format(),
//    Posted_Date__c = Date.newInstance(2010 + j, 1, 2), Amount__c = 20));
//  }

  system.assertEquals(date.newInstance(2010, 1, 2), payments.get(0).Posted_Date__c);