NullPointerArgumentEvaluatorTest.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2023-02-22
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <string>
  12. using namespace ls::std::core;
  13. using namespace ::std;
  14. namespace
  15. {
  16. class NullPointerArgumentEvaluatorTest : public ::testing::Test
  17. {
  18. protected:
  19. NullPointerArgumentEvaluatorTest() = default;
  20. ~NullPointerArgumentEvaluatorTest() override = default;
  21. void SetUp() override
  22. {}
  23. void TearDown() override
  24. {}
  25. };
  26. TEST_F(NullPointerArgumentEvaluatorTest, evaluate)
  27. {
  28. EXPECT_THROW(
  29. {
  30. try
  31. {
  32. NullPointerArgumentEvaluator{nullptr}.evaluate();
  33. }
  34. catch (const IllegalArgumentException &_exception)
  35. {
  36. string actual = _exception.what();
  37. string expected = _exception.getName() + " thrown - passed argument is null!";
  38. ASSERT_STREQ(expected.c_str(), actual.c_str());
  39. throw;
  40. }
  41. },
  42. IllegalArgumentException);
  43. }
  44. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_dedicated_message)
  45. {
  46. EXPECT_THROW(
  47. {
  48. try
  49. {
  50. NullPointerArgumentEvaluator(nullptr, "this reference is null!").evaluate();
  51. }
  52. catch (const IllegalArgumentException &_exception)
  53. {
  54. string actual = _exception.what();
  55. string expected = _exception.getName() + " thrown - this reference is null!";
  56. ASSERT_STREQ(expected.c_str(), actual.c_str());
  57. throw;
  58. }
  59. },
  60. IllegalArgumentException);
  61. }
  62. }