/*
* Author:          Patrick-Christopher Mattulat
 * Co-Author:       Claude Sonnet 4.6 (LLM)
* Company:         Lynar Studios
* E-Mail:          webmaster@lynarstudios.com
* Created:         2023-04-08
* Changed:         2026-06-23
*
* */

#include <gtest/gtest.h>
#include <ls-std/ls-std-core-jni.hpp>
#include <ls-std/ls-std-core.hpp>
#include <memory>
#include <string>

using ls::standard::core::IllegalArgumentException;
using ls::standard::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"};
    auto methodId = (jmethodID) make_shared<int>().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());
  }
}
