ApexSensei

Drills Unit testing

Use a fake collaborator

extends makes your class a child; override replaces a parent method marked virtual.

Your task

Finish the fake gateway so tests can read what was sent, get a set reply, and force one failure.

@IsTest
public class AS_CA2B6F4305F6_FakeGateway extends AS_CA2B6F4305F6_Gateway {
    public List<String> sentPayloads = new List<String>();
    public Boolean failNext = false;

    public override String send(String payload) {
        return null;
    }

    @IsTest
    static void capturesMessage() {
        AS_CA2B6F4305F6_FakeGateway fake = new AS_CA2B6F4305F6_FakeGateway();
        String result = AS_CA2B6F4305F6_Notifier.deliver(fake, 'Login');
        Assert.areEqual('ACK:CASE:Login', result);
        Assert.areEqual('CASE:Login', fake.sentPayloads[0]);
    }
}

Requirements

  1. returnsDeterministicAck should pass
  2. capturesOrderedPayloads should pass
  3. preservesEmptySubject should pass
  4. simulatesOneFailure should pass

Sign in to open this drill