Bladeren bron

Improve KvParser class test coverage

- add missing test cases
Patrick-Christopher Mattulat 2 jaren geleden
bovenliggende
commit
bf29847732
2 gewijzigde bestanden met toevoegingen van 43 en 10 verwijderingen
  1. 3 3
      source/ls_std/io/kv/KvParser.cpp
  2. 40 7
      test/cases/io/kv/KvParserTest.cpp

+ 3 - 3
source/ls_std/io/kv/KvParser.cpp

@@ -3,13 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2021-05-02
+ * Changed:         2021-07-15
  *
  * */
 
 #include <ls_std/io/kv/KvParser.hpp>
-#include <ls_std/exception/NullPointerException.hpp>
 #include <ls_std/io/NewLine.hpp>
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
 ls_std::KvParser::KvParser(const std::shared_ptr<ls_std::KvDocument> &_document) : ls_std::Class("KvParser")
 {
@@ -35,7 +35,7 @@ void ls_std::KvParser::_assignDocument(const std::shared_ptr<ls_std::KvDocument>
 {
   if (_document == nullptr)
   {
-    throw ls_std::NullPointerException{};
+    throw ls_std::IllegalArgumentException{};
   }
 
   this->document = _document;

+ 40 - 7
test/cases/io/kv/KvParserTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2021-05-02
+ * Changed:         2021-07-15
  *
  * */
 
@@ -26,6 +26,20 @@ namespace
       {}
   };
 
+  TEST_F(KvParserTest, constructor_no_document_reference)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::KvParser parser{nullptr};
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   TEST_F(KvParserTest, getDocument)
   {
     ls_std::KvParser parser{std::make_shared<ls_std::KvDocument>()};
@@ -51,13 +65,32 @@ namespace
 
   TEST_F(KvParserTest, setDocument)
   {
-    std::shared_ptr<ls_std::KvDocument> document1 = std::make_shared<ls_std::KvDocument>();
-    std::shared_ptr<ls_std::KvDocument> document2 = std::make_shared<ls_std::KvDocument>();
+    // preparation
+
+    std::shared_ptr<ls_std::KvDocument> document = std::make_shared<ls_std::KvDocument>();
+    ls_std::KvParser parser{document};
 
-    ls_std::KvParser parser{document1};
-    ASSERT_TRUE(parser.getDocument() == document1);
+    // set and check
+
+    std::shared_ptr<ls_std::KvDocument> newDocument = std::make_shared<ls_std::KvDocument>();
+    parser.setDocument(newDocument);
+    ASSERT_TRUE(parser.getDocument() == newDocument);
+  }
+
+  TEST_F(KvParserTest, setDocument_no_reference)
+  {
+    std::shared_ptr<ls_std::KvDocument> document = std::make_shared<ls_std::KvDocument>();
+    ls_std::KvParser parser{document};
 
-    parser.setDocument(document2);
-    ASSERT_TRUE(parser.getDocument() == document2);
+    EXPECT_THROW({
+                   try
+                   {
+                     parser.setDocument(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
   }
 }