NullPointerArgumentEvaluatorTest.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. using namespace ::testing;
  15. namespace
  16. {
  17. class NullPointerArgumentEvaluatorTest : public Test
  18. {
  19. protected:
  20. NullPointerArgumentEvaluatorTest() = default;
  21. ~NullPointerArgumentEvaluatorTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(NullPointerArgumentEvaluatorTest, evaluate)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. NullPointerArgumentEvaluator{nullptr}.evaluate();
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. string actual = _exception.what();
  38. string expected = _exception.getName() + " thrown - passed argument is null!";
  39. ASSERT_STREQ(expected.c_str(), actual.c_str());
  40. throw;
  41. }
  42. },
  43. IllegalArgumentException);
  44. }
  45. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_dedicated_message)
  46. {
  47. EXPECT_THROW(
  48. {
  49. try
  50. {
  51. NullPointerArgumentEvaluator(nullptr, "this reference is null!").evaluate();
  52. }
  53. catch (const IllegalArgumentException &_exception)
  54. {
  55. string actual = _exception.what();
  56. string expected = _exception.getName() + " thrown - this reference is null!";
  57. ASSERT_STREQ(expected.c_str(), actual.c_str());
  58. throw;
  59. }
  60. },
  61. IllegalArgumentException);
  62. }
  63. }