@@ -34,6 +34,10 @@ private class TriggerActionFlowTest {
3434 private static final String ONE_ERROR = ' There should be exactly one error' ;
3535 private static final String SAMPLE_FLOW_NAME = ' TriggerActionFlowTest' ;
3636 private static final String TEST = ' Test!' ;
37+ private static final String SAMPLE_FLOW_TYPE_NAME =
38+ TriggerActionFlow .FLOW_INTERVIEW_PREFIX +
39+ ' .' +
40+ SAMPLE_FLOW_NAME ;
3741
3842 private static Account myAccount = new Account (
3943 Name = MY_ACCOUNT ,
@@ -359,6 +363,114 @@ private class TriggerActionFlowTest {
359363 );
360364 }
361365
366+ @IsTest
367+ private static void bypassWithTypeShouldSucceed () {
368+ TriggerActionFlow .nameExtractor = new FakeNameExtractor (
369+ SAMPLE_FLOW_TYPE_NAME
370+ );
371+ TriggerActionFlow .bypass (Flow .Interview .TriggerActionFlowTest .class );
372+
373+ System .Assert .isTrue (
374+ TriggerActionFlow .bypassedFlows .contains (SAMPLE_FLOW_NAME ),
375+ BYPASSES_SHOULD_BE_POPULATED_CORRECTLY
376+ );
377+ }
378+
379+ @IsTest
380+ private static void clearBypassWithTypeShouldSucceed () {
381+ TriggerActionFlow .nameExtractor = new FakeNameExtractor (
382+ SAMPLE_FLOW_TYPE_NAME
383+ );
384+ TriggerActionFlow .bypass (Flow .Interview .TriggerActionFlowTest .class );
385+ TriggerActionFlow .clearBypass (Flow .Interview .TriggerActionFlowTest .class );
386+
387+ System .Assert .isFalse (
388+ TriggerActionFlow .bypassedFlows .contains (SAMPLE_FLOW_NAME ),
389+ BYPASSES_SHOULD_BE_POPULATED_CORRECTLY
390+ );
391+ }
392+
393+ @IsTest
394+ private static void isBypassedWithTypeShouldSucceed () {
395+ TriggerActionFlow .nameExtractor = new FakeNameExtractor (
396+ SAMPLE_FLOW_TYPE_NAME
397+ );
398+ Boolean isBypassed ;
399+ TriggerActionFlow .bypass (Flow .Interview .TriggerActionFlowTest .class );
400+
401+ isBypassed = TriggerActionFlow .isBypassed (
402+ Flow .Interview .TriggerActionFlowTest .class
403+ );
404+
405+ System .Assert .isTrue (isBypassed , BYPASSES_SHOULD_BE_POPULATED_CORRECTLY );
406+ }
407+
408+ @IsTest
409+ private static void bypassWithInvalidTypeShouldThrowException () {
410+ try {
411+ TriggerActionFlow .bypass (String .class );
412+ } catch (Exception e ) {
413+ myException = e ;
414+ }
415+
416+ System .Assert .areNotEqual (null , myException , EXCEPTION_SHOULD_BE_THROWN );
417+ System .Assert .areEqual (
418+ true ,
419+ myException .getMessage ().contains (' Type must represent a Flow' ),
420+ EXCEPTION_SHOULD_HAVE_THE_CORRECT_MESSAGE
421+ );
422+ }
423+
424+ @IsTest
425+ private static void clearBypassWithInvalidTypeShouldThrowException () {
426+ try {
427+ TriggerActionFlow .clearBypass (String .class );
428+ } catch (Exception e ) {
429+ myException = e ;
430+ }
431+
432+ System .Assert .areNotEqual (null , myException , EXCEPTION_SHOULD_BE_THROWN );
433+ System .Assert .areEqual (
434+ true ,
435+ myException .getMessage ().contains (' Type must represent a Flow' ),
436+ EXCEPTION_SHOULD_HAVE_THE_CORRECT_MESSAGE
437+ );
438+ }
439+
440+ @IsTest
441+ private static void isBypassedWithInvalidTypeShouldThrowException () {
442+ try {
443+ TriggerActionFlow .isBypassed (String .class );
444+ } catch (Exception e ) {
445+ myException = e ;
446+ }
447+
448+ System .Assert .areNotEqual (null , myException , EXCEPTION_SHOULD_BE_THROWN );
449+ System .Assert .areEqual (
450+ true ,
451+ myException .getMessage ().contains (' Type must represent a Flow' ),
452+ EXCEPTION_SHOULD_HAVE_THE_CORRECT_MESSAGE
453+ );
454+ }
455+
456+ @IsTest
457+ private static void bypassWithNonExistentFlowShouldThrowException () {
458+ try {
459+ TriggerActionFlow .bypass (
460+ Flow .Interview .SomeBogusClassWhichDoesNotExist .class
461+ );
462+ } catch (Exception e ) {
463+ myException = e ;
464+ }
465+
466+ System .Assert .areNotEqual (null , myException , EXCEPTION_SHOULD_BE_THROWN );
467+ System .Assert .areEqual (
468+ true ,
469+ myException .getMessage ().contains (' Flow does not exist' ),
470+ EXCEPTION_SHOULD_HAVE_THE_CORRECT_MESSAGE
471+ );
472+ }
473+
362474 @IsTest
363475 private static void invokeFlowShouldReturnUnsuccessfulResponseWithBogusFlowName () {
364476 List <Invocable .Action .Result > results = new TriggerActionFlow .InvocableAction ()
@@ -454,4 +566,16 @@ private class TriggerActionFlowTest {
454566 );
455567 }
456568 }
569+
570+ private class FakeNameExtractor extends TriggerActionFlow .NameExtractor {
571+ private String mockTypeName ;
572+
573+ public FakeNameExtractor (String mockTypeName ) {
574+ this .mockTypeName = mockTypeName ;
575+ }
576+
577+ public override String extractName (System.Type flowType ) {
578+ return this .mockTypeName ;
579+ }
580+ }
457581}
0 commit comments