فهرست منبع

Add dedicated exception messages to JNI related classes

Patrick-Christopher Mattulat 1 سال پیش
والد
کامیت
9fb96fb87a

+ 1 - 1
source/ls-std/core/jni/JniApi.cpp

@@ -16,7 +16,7 @@ using std::string;
 
 JniApi::JniApi(JNIEnv *_environment)
 {
-  NullPointerArgumentEvaluator{_environment}.evaluate();
+  NullPointerArgumentEvaluator{_environment, "Java environment is not being provided!"}.evaluate();
   this->environment = _environment;
 }
 

+ 3 - 3
source/ls-std/core/jni/JniClass.cpp

@@ -32,9 +32,9 @@ using std::string;
 
 JniClass::JniClass(const shared_ptr<JniClassParameter> &_parameter, const string &_path)
 {
-  NullPointerArgumentEvaluator{_parameter}.evaluate();
-  EmptyStringArgumentEvaluator{_path}.evaluate();
-  NullPointerArgumentEvaluator{_parameter->getJavaEnvironment()}.evaluate();
+  NullPointerArgumentEvaluator{_parameter, "no provided reference to JNI class parameter!"}.evaluate();
+  EmptyStringArgumentEvaluator{_path, "path to associated Java class is empty!"}.evaluate();
+  NullPointerArgumentEvaluator{_parameter->getJavaEnvironment(), "Java environment is not being provided!"}.evaluate();
   this->parameter = _parameter;
   this->path = _path;
   ConditionalFunctionExecutor{_parameter->getJniApi() == nullptr}.execute([this]() { _createJniApi(); });

+ 2 - 2
source/ls-std/core/jni/JniMethod.cpp

@@ -16,8 +16,8 @@ using std::string;
 
 JniMethod::JniMethod(const string &_methodIdentifier, const string &_methodSignature)
 {
-  EmptyStringArgumentEvaluator{_methodIdentifier}.evaluate();
-  EmptyStringArgumentEvaluator{_methodSignature}.evaluate();
+  EmptyStringArgumentEvaluator{_methodIdentifier, "no method identifier has been provided!"}.evaluate();
+  EmptyStringArgumentEvaluator{_methodSignature, "no method signature has been provided!"}.evaluate();
   this->methodIdentifier = _methodIdentifier;
   this->methodSignature = _methodSignature;
 }

+ 7 - 0
test/cases/core/jni/JniApiTest.cpp

@@ -10,9 +10,11 @@
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core-jni.hpp>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using ls::std::core::IllegalArgumentException;
 using ls::std::core::experimental::JniApi;
+using std::string;
 using testing::Test;
 
 namespace
@@ -35,6 +37,11 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+
+            string expected = _exception.getName() + " thrown - Java environment is not being provided!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 12 - 0
test/cases/core/jni/JniClassTest.cpp

@@ -59,6 +59,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+            string expected = _exception.getName() + " thrown - no provided reference to JNI class parameter!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -75,6 +79,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+            string expected = _exception.getName() + " thrown - path to associated Java class is empty!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -91,6 +99,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+            string expected = _exception.getName() + " thrown - Java environment is not being provided!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 10 - 0
test/cases/core/jni/JniMethodTest.cpp

@@ -11,10 +11,12 @@
 #include <ls-std/ls-std-core-jni.hpp>
 #include <ls-std/ls-std-core.hpp>
 #include <memory>
+#include <string>
 
 using ls::std::core::IllegalArgumentException;
 using ls::std::core::experimental::JniMethod;
 using std::make_shared;
+using std::string;
 using testing::Test;
 
 namespace
@@ -37,6 +39,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+            string expected = _exception.getName() + " thrown - no method identifier has been provided!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -53,6 +59,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
+            string expected = _exception.getName() + " thrown - no method signature has been provided!";
+            string actual = _exception.what();
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },