Last active
November 16, 2018 22:00
-
-
Save melissajhansen/723711339f51f7bf168875c9f5d6e7b8 to your computer and use it in GitHub Desktop.
This file contains 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 class HandleBadMethodsTest { | |
@isTest | |
static void testCustomException() { | |
//validate that our method will reject negative integers | |
Boolean exceptionWasThrown = false; | |
try { | |
SampleBadMethods.iAddUpPositiveIntegers(-1,5); | |
} catch (SampleBadMethods.SampleCustomException e) { | |
//This assert verifies the correct error message was thrown | |
System.assertEquals(e.getMessage(), 'I only take positive integers!'); | |
exceptionWasThrown = true; | |
} | |
//This assert verifies that an exception was indeed thrown. The above assert is insufficient, | |
//because the test would pass even if no exception was thrown at all | |
System.assertEquals(exceptionWasThrown, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment