Преглед на файлове

Increase test coverage of SerializableJsonEvent class

Patrick-Christopher Mattulat преди 3 години
родител
ревизия
3441621fb0

+ 3 - 3
source/ls_std/serialization/json/event/SerializableJsonEvent.cpp

@@ -3,12 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2021-05-02
+ * Changed:         2021-09-19
  *
  * */
 
 #include <ls_std/serialization/json/event/SerializableJsonEvent.hpp>
-#include <ls_std/exception/NullPointerException.hpp>
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
 ls_std::SerializableJsonEvent::SerializableJsonEvent(const std::shared_ptr<ls_std::Event> &_value) : ls_std::Class("SerializableJsonEvent")
 {
@@ -43,7 +43,7 @@ void ls_std::SerializableJsonEvent::_assignValue(const std::shared_ptr<ls_std::E
 {
   if (_value == nullptr)
   {
-    throw ls_std::NullPointerException{};
+    throw ls_std::IllegalArgumentException{};
   }
 
   this->value = _value;

+ 32 - 1
test/cases/serialization/json/event/SerializableJsonEventTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-20
- * Changed:         2021-05-02
+ * Changed:         2021-09-19
  *
  * */
 
@@ -26,6 +26,20 @@ namespace
       {}
   };
 
+  TEST_F(SerializableJsonEventTest, constructor_parameter_not_set)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::SerializableJsonEvent serializable{nullptr};
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   TEST_F(SerializableJsonEventTest, marshal)
   {
     ls_std::Event event{"OPEN_DOOR_EVENT"};
@@ -55,4 +69,21 @@ namespace
     ASSERT_STREQ("16675", parameterList.at("door_id").c_str());
     ASSERT_STREQ("true", parameterList.at("key_available").c_str());
   }
+
+  TEST_F(SerializableJsonEventTest, setValue_parameter_not_set)
+  {
+    ls_std::Event event{"TMP_EVENT"};
+    ls_std::SerializableJsonEvent serializable{std::make_shared<ls_std::Event>(event)};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     serializable.setValue(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
 }