Skip to content

Instantly share code, notes, and snippets.

@albarivas
Created November 10, 2022 13:01
Show Gist options
  • Save albarivas/fa85b5a1b795e0fd9d22b376e5a72901 to your computer and use it in GitHub Desktop.
Save albarivas/fa85b5a1b795e0fd9d22b376e5a72901 to your computer and use it in GitHub Desktop.
@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