Created
November 10, 2022 13:01
-
-
Save albarivas/fa85b5a1b795e0fd9d22b376e5a72901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private with sharing class SampleBadMethodsTest { | |
@isTest | |
private static void iAddUpPositiveIntegers_positive() { // Happy path | |
// GIVEN | |
Integer a = 10; | |
Integer b = 20; | |
// WHEN | |
Test.startTest(); | |
Integer result = SampleBadMethods.iAddUpPositiveIntegers(a, b); | |
Test.stopTest(); | |
// THEN | |
System.assertEquals(30, result); | |
} | |
@isTest | |
private static void iAddUpPositiveIntegers_aIsNegative() { | |
// GIVEN | |
Integer a = -10; | |
Integer b = 20; | |
// WHEN | |
try { | |
Test.startTest(); | |
Integer result = SampleBadMethods.iAddUpPositiveIntegers(a, b); | |
Test.stopTest(); | |
System.assert(false, 'Exception expected'); | |
} catch(Exception e) { | |
// THEN | |
System.assert(e.getMessage().contains('I only take positive integers!')); | |
} | |
} | |
@isTest | |
private static void iAddUpPositiveIntegers_bIsNegative() { | |
// GIVEN | |
Integer a = 10; | |
Integer b = -20; | |
// WHEN | |
try { | |
Test.startTest(); | |
Integer result = SampleBadMethods.iAddUpPositiveIntegers(a, b); | |
Test.stopTest(); | |
System.assert(false, 'Exception expected'); | |
} catch(Exception e) { | |
// THEN | |
System.assert(e.getMessage().contains('I only take positive integers!')); | |
} | |
} | |
@isTest | |
private static void iAddUpPositiveIntegers_aIsNull() { | |
// GIVEN | |
Integer a = null; | |
Integer b = 20; | |
// WHEN | |
try { | |
Test.startTest(); | |
Integer result = SampleBadMethods.iAddUpPositiveIntegers(a, b); | |
Test.stopTest(); | |
System.assert(false, 'Exception expected'); | |
} catch(Exception e) { | |
// THEN | |
System.assert(e.getMessage().contains('I only take positive integers!')); | |
} | |
} | |
@isTest | |
private static void iAddUpPositiveIntegers_bIsNull() { | |
// GIVEN | |
Integer a = 20; | |
Integer b = null; | |
// WHEN | |
try { | |
Test.startTest(); | |
Integer result = SampleBadMethods.iAddUpPositiveIntegers(a, b); | |
Test.stopTest(); | |
System.assert(false, 'Exception expected'); | |
} catch(Exception e) { | |
// THEN | |
System.assert(e.getMessage().contains('I only take positive integers!')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment