NullPointerArgumentEvaluatorTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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-08
  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 message = _exception.what();
  37. ASSERT_STREQ("IllegalArgumentException thrown - passed argument is null!", message.c_str());
  38. throw;
  39. }
  40. },
  41. IllegalArgumentException);
  42. }
  43. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_dedicated_message)
  44. {
  45. EXPECT_THROW(
  46. {
  47. try
  48. {
  49. NullPointerArgumentEvaluator(nullptr, "this reference is null!").evaluate();
  50. }
  51. catch (const IllegalArgumentException &_exception)
  52. {
  53. string message = _exception.what();
  54. ASSERT_STREQ("IllegalArgumentException thrown - this reference is null!", message.c_str());
  55. throw;
  56. }
  57. },
  58. IllegalArgumentException);
  59. }
  60. }