/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2023-04-08 * Changed: 2023-04-10 * * */ #include #include #include #include #include using ls::std::core::IllegalArgumentException; using ls::std::core::experimental::JniMethod; using std::make_shared; using std::string; using testing::Test; namespace { class JniMethodTest : public Test { public: JniMethodTest() = default; ~JniMethodTest() override = default; }; TEST_F(JniMethodTest, constructor_empty_method_identifier) { EXPECT_THROW( { try { JniMethod method("", "()B"); } 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; } }, IllegalArgumentException); } TEST_F(JniMethodTest, constructor_empty_method_signature) { EXPECT_THROW( { try { JniMethod method("getDay", ""); } 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; } }, IllegalArgumentException); } TEST_F(JniMethodTest, getMethodId) { JniMethod method{"getDay", "()B"}; ASSERT_TRUE(method.getMethodId() == nullptr); } TEST_F(JniMethodTest, getMethodIdentifier) { JniMethod method{"getDay", "()B"}; ASSERT_STREQ("getDay", method.getMethodIdentifier().c_str()); } TEST_F(JniMethodTest, getMethodSignature) { JniMethod method{"getDay", "()B"}; ASSERT_STREQ("()B", method.getMethodSignature().c_str()); } TEST_F(JniMethodTest, setMethodId) { JniMethod method{"getDay", "()B"}; jmethodID methodId = (jmethodID) make_shared().get(); method.setMethodId(methodId); ASSERT_TRUE(method.getMethodId() == methodId); } TEST_F(JniMethodTest, setMethodIdentifier) { JniMethod method{"getDay", "()B"}; method.setMethodIdentifier("getHour"); ASSERT_STREQ("getHour", method.getMethodIdentifier().c_str()); } TEST_F(JniMethodTest, setMethodSignature) { JniMethod method{"getDay", "()B"}; method.setMethodSignature("()I"); ASSERT_STREQ("()I", method.getMethodSignature().c_str()); } }