You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 rivejä
1.5 KiB

  1. @IsTest
  2. public with sharing class MassTransactorBatchHelperTest {
  3. public static Boolean onFinishCalled = false;
  4. @IsTest
  5. public static void testIterable() {
  6. Contact c1 = new Contact(LastName='Contact 1');
  7. Contact c2 = new Contact(LastName='Contact 2');
  8. List<Contact> contacts = new List<Contact>{c1, c2};
  9. MassTransactorBatchHelper.ListIterable itbl = new MassTransactorBatchHelper.ListIterable(contacts);
  10. Iterator<SObject> it = itbl.Iterator();
  11. System.assert(it.hasNext());
  12. System.assert(((Contact)it.next()).LastName == 'Contact 1');
  13. System.assert(it.hasNext());
  14. System.assert(((Contact)it.next()).LastName == 'Contact 2');
  15. System.assert(!it.hasNext());
  16. }
  17. @IsTest
  18. public static void testCallsFinishAction() {
  19. Contact c1 = new Contact(LastName='Contact 1');
  20. Contact c2 = new Contact(LastName='Contact 2');
  21. List<Contact> contacts = new List<Contact>{c1, c2};
  22. SimpleFinishAction action = new SimpleFinishAction();
  23. MassTransactorBatchHelper bh = new MassTransactorBatchHelper(contacts, 'create', action);
  24. Test.startTest();
  25. Database.executeBatch(bh);
  26. Test.stopTest();
  27. System.assert(onFinishCalled);
  28. }
  29. public class SimpleFinishAction implements MassTransactorBatchHelper.OnFinishAction {
  30. public void onFinish(Id jobId) {
  31. MassTransactorBatchHelperTest.onFinishCalled = true;
  32. }
  33. }
  34. }