IllegalArgumentExceptionTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2021-05-01
  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 ::testing;
  14. using namespace ::std;
  15. namespace
  16. {
  17. class IllegalArgumentExceptionTest : public Test
  18. {
  19. protected:
  20. IllegalArgumentExceptionTest() = default;
  21. ~IllegalArgumentExceptionTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(IllegalArgumentExceptionTest, constructor)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. throw IllegalArgumentException{};
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. string actual = _exception.what();
  38. string expected = _exception.getName() + " thrown - passed argument is not valid!";
  39. EXPECT_STREQ(expected.c_str(), actual.c_str());
  40. throw;
  41. }
  42. },
  43. IllegalArgumentException);
  44. }
  45. TEST_F(IllegalArgumentExceptionTest, constructor_dedicated_message)
  46. {
  47. EXPECT_THROW(
  48. {
  49. try
  50. {
  51. throw IllegalArgumentException{"value is empty"};
  52. }
  53. catch (const IllegalArgumentException &_exception)
  54. {
  55. string actual = _exception.what();
  56. string expected = _exception.getName() + " thrown - value is empty";
  57. EXPECT_STREQ(expected.c_str(), actual.c_str());
  58. throw;
  59. }
  60. },
  61. IllegalArgumentException);
  62. }
  63. TEST_F(IllegalArgumentExceptionTest, getName)
  64. {
  65. ASSERT_STREQ("IllegalArgumentException", IllegalArgumentException{}.getName().c_str());
  66. }
  67. }