Ver Fonte

Add EventNotHandledException

- add dedicated exception for indicating that
an event was not handled
- add test for EventNotHandledException class
Patrick-Christopher Mattulat há 3 anos atrás
pai
commit
bc49b7a82f

+ 1 - 0
CMakeLists.txt

@@ -172,6 +172,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/boxing/SerializableJsonStringFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/event/SerializableJsonEventFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/factory/SerializableTestFactory.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/EventNotHandledExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/EventNotSubscribedExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/FileNotFoundExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/FileOperationExceptionTest.cpp

+ 30 - 0
include/ls_std/exception/EventNotHandledException.hpp

@@ -0,0 +1,30 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-27
+ * Changed:         2021-05-27
+ *
+ * */
+
+#ifndef LS_STD_EVENT_NOT_HANDLED_EXCEPTION_HPP
+#define LS_STD_EVENT_NOT_HANDLED_EXCEPTION_HPP
+
+#include <exception>
+
+namespace ls_std
+{
+  class EventNotHandledException : public std::exception
+  {
+    public:
+
+      EventNotHandledException() = default;
+
+      const char *what() const noexcept override
+      {
+        return "EventNotHandledException thrown - event was not handled - nothing happened!";
+      };
+  };
+}
+
+#endif

+ 1 - 0
include/ls_std/ls_std.hpp

@@ -27,6 +27,7 @@
 #include "boxing/Long.hpp"
 #include "boxing/String.hpp"
 
+#include "exception/EventNotHandledException.hpp"
 #include "exception/EventNotSubscribedException.hpp"
 #include "exception/FileNotFoundException.hpp"
 #include "exception/FileOperationException.hpp"

+ 43 - 0
test/cases/exception/EventNotHandledExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-27
+ * Changed:         2021-05-27
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class EventNotHandledExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      EventNotHandledExceptionTest() = default;
+      ~EventNotHandledExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(EventNotHandledExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::EventNotHandledException{};
+                   }
+                   catch (const ls_std::EventNotHandledException &_exception)
+                   {
+                     EXPECT_STREQ("EventNotHandledException thrown - event was not handled - nothing happened!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::EventNotHandledException);
+  }
+}