text:
require "helper"

require "gapic/grpc/service_stub"

require "google/cloud/kms/v1/service_pb"
require "google/cloud/kms/v1/service_services_pb"
require "google/cloud/kms/v1/key_management_service"

class ::Google::Cloud::Kms::V1::KeyManagementService::ClientTest < Minitest::Test
  class ClientStub
    attr_accessor :call_rpc_count, :requests

    def initialize response, operation, &block
      @response = response
      @operation = operation
      @block = block
      @call_rpc_count = 0
      @requests = []
    end

    def call_rpc *args, **kwargs
      @call_rpc_count += 1

      @requests << @block&.call(*args, **kwargs)

      yield @response, @operation if block_given?

      @response
    end
  end

  def test_list_key_rings
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ListKeyRingsResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    page_size = 42
    page_token = "hello world"
    filter = "hello world"
    order_by = "hello world"

    list_key_rings_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list_key_rings, name
      assert_kind_of ::Google::Cloud::Kms::V1::ListKeyRingsRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal 42, request["page_size"]
      assert_equal "hello world", request["page_token"]
      assert_equal "hello world", request["filter"]
      assert_equal "hello world", request["order_by"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_key_rings_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list_key_rings({ parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by }) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list_key_rings parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list_key_rings ::Google::Cloud::Kms::V1::ListKeyRingsRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list_key_rings({ parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by }, grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list_key_rings(::Google::Cloud::Kms::V1::ListKeyRingsRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by), grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_key_rings_client_stub.call_rpc_count
    end
  end

  def test_list_crypto_keys
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ListCryptoKeysResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    page_size = 42
    page_token = "hello world"
    version_view = :CRYPTO_KEY_VERSION_VIEW_UNSPECIFIED
    filter = "hello world"
    order_by = "hello world"

    list_crypto_keys_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list_crypto_keys, name
      assert_kind_of ::Google::Cloud::Kms::V1::ListCryptoKeysRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal 42, request["page_size"]
      assert_equal "hello world", request["page_token"]
      assert_equal :CRYPTO_KEY_VERSION_VIEW_UNSPECIFIED, request["version_view"]
      assert_equal "hello world", request["filter"]
      assert_equal "hello world", request["order_by"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_crypto_keys_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list_crypto_keys({ parent: parent, page_size: page_size, page_token: page_token, version_view: version_view, filter: filter, order_by: order_by }) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list_crypto_keys parent: parent, page_size: page_size, page_token: page_token, version_view: version_view, filter: filter, order_by: order_by do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list_crypto_keys ::Google::Cloud::Kms::V1::ListCryptoKeysRequest.new(parent: parent, page_size: page_size, page_token: page_token, version_view: version_view, filter: filter, order_by: order_by) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list_crypto_keys({ parent: parent, page_size: page_size, page_token: page_token, version_view: version_view, filter: filter, order_by: order_by }, grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list_crypto_keys(::Google::Cloud::Kms::V1::ListCryptoKeysRequest.new(parent: parent, page_size: page_size, page_token: page_token, version_view: version_view, filter: filter, order_by: order_by), grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_crypto_keys_client_stub.call_rpc_count
    end
  end

  def test_list_crypto_key_versions
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ListCryptoKeyVersionsResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    page_size = 42
    page_token = "hello world"
    view = :CRYPTO_KEY_VERSION_VIEW_UNSPECIFIED
    filter = "hello world"
    order_by = "hello world"

    list_crypto_key_versions_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list_crypto_key_versions, name
      assert_kind_of ::Google::Cloud::Kms::V1::ListCryptoKeyVersionsRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal 42, request["page_size"]
      assert_equal "hello world", request["page_token"]
      assert_equal :CRYPTO_KEY_VERSION_VIEW_UNSPECIFIED, request["view"]
      assert_equal "hello world", request["filter"]
      assert_equal "hello world", request["order_by"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_crypto_key_versions_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list_crypto_key_versions({ parent: parent, page_size: page_size, page_token: page_token, view: view, filter: filter, order_by: order_by }) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list_crypto_key_versions parent: parent, page_size: page_size, page_token: page_token, view: view, filter: filter, order_by: order_by do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list_crypto_key_versions ::Google::Cloud::Kms::V1::ListCryptoKeyVersionsRequest.new(parent: parent, page_size: page_size, page_token: page_token, view: view, filter: filter, order_by: order_by) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list_crypto_key_versions({ parent: parent, page_size: page_size, page_token: page_token, view: view, filter: filter, order_by: order_by }, grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list_crypto_key_versions(::Google::Cloud::Kms::V1::ListCryptoKeyVersionsRequest.new(parent: parent, page_size: page_size, page_token: page_token, view: view, filter: filter, order_by: order_by), grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_crypto_key_versions_client_stub.call_rpc_count
    end
  end

  def test_list_import_jobs
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ListImportJobsResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    page_size = 42
    page_token = "hello world"
    filter = "hello world"
    order_by = "hello world"

    list_import_jobs_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list_import_jobs, name
      assert_kind_of ::Google::Cloud::Kms::V1::ListImportJobsRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal 42, request["page_size"]
      assert_equal "hello world", request["page_token"]
      assert_equal "hello world", request["filter"]
      assert_equal "hello world", request["order_by"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_import_jobs_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list_import_jobs({ parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by }) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list_import_jobs parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list_import_jobs ::Google::Cloud::Kms::V1::ListImportJobsRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list_import_jobs({ parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by }, grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list_import_jobs(::Google::Cloud::Kms::V1::ListImportJobsRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter, order_by: order_by), grpc_options) do |response, operation|
        assert_kind_of Gapic::PagedEnumerable, response
        assert_equal grpc_response, response.response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_import_jobs_client_stub.call_rpc_count
    end
  end

  def test_get_key_ring
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::KeyRing.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    get_key_ring_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get_key_ring, name
      assert_kind_of ::Google::Cloud::Kms::V1::GetKeyRingRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_key_ring_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get_key_ring({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get_key_ring name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get_key_ring ::Google::Cloud::Kms::V1::GetKeyRingRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get_key_ring({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get_key_ring(::Google::Cloud::Kms::V1::GetKeyRingRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_key_ring_client_stub.call_rpc_count
    end
  end

  def test_get_crypto_key
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKey.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    get_crypto_key_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get_crypto_key, name
      assert_kind_of ::Google::Cloud::Kms::V1::GetCryptoKeyRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_crypto_key_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get_crypto_key({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get_crypto_key name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get_crypto_key ::Google::Cloud::Kms::V1::GetCryptoKeyRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get_crypto_key({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get_crypto_key(::Google::Cloud::Kms::V1::GetCryptoKeyRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_crypto_key_client_stub.call_rpc_count
    end
  end

  def test_get_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    get_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::GetCryptoKeyVersionRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get_crypto_key_version({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get_crypto_key_version name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get_crypto_key_version ::Google::Cloud::Kms::V1::GetCryptoKeyVersionRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get_crypto_key_version({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get_crypto_key_version(::Google::Cloud::Kms::V1::GetCryptoKeyVersionRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_get_public_key
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::PublicKey.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    get_public_key_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get_public_key, name
      assert_kind_of ::Google::Cloud::Kms::V1::GetPublicKeyRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_public_key_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get_public_key({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get_public_key name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get_public_key ::Google::Cloud::Kms::V1::GetPublicKeyRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get_public_key({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get_public_key(::Google::Cloud::Kms::V1::GetPublicKeyRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_public_key_client_stub.call_rpc_count
    end
  end

  def test_get_import_job
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ImportJob.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    get_import_job_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get_import_job, name
      assert_kind_of ::Google::Cloud::Kms::V1::GetImportJobRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_import_job_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get_import_job({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get_import_job name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get_import_job ::Google::Cloud::Kms::V1::GetImportJobRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get_import_job({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get_import_job(::Google::Cloud::Kms::V1::GetImportJobRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_import_job_client_stub.call_rpc_count
    end
  end

  def test_create_key_ring
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::KeyRing.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    key_ring_id = "hello world"
    key_ring = {}

    create_key_ring_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :create_key_ring, name
      assert_kind_of ::Google::Cloud::Kms::V1::CreateKeyRingRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal "hello world", request["key_ring_id"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::KeyRing), request["key_ring"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, create_key_ring_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.create_key_ring({ parent: parent, key_ring_id: key_ring_id, key_ring: key_ring }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.create_key_ring parent: parent, key_ring_id: key_ring_id, key_ring: key_ring do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.create_key_ring ::Google::Cloud::Kms::V1::CreateKeyRingRequest.new(parent: parent, key_ring_id: key_ring_id, key_ring: key_ring) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.create_key_ring({ parent: parent, key_ring_id: key_ring_id, key_ring: key_ring }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.create_key_ring(::Google::Cloud::Kms::V1::CreateKeyRingRequest.new(parent: parent, key_ring_id: key_ring_id, key_ring: key_ring), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, create_key_ring_client_stub.call_rpc_count
    end
  end

  def test_create_crypto_key
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKey.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    crypto_key_id = "hello world"
    crypto_key = {}
    skip_initial_version_creation = true

    create_crypto_key_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :create_crypto_key, name
      assert_kind_of ::Google::Cloud::Kms::V1::CreateCryptoKeyRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal "hello world", request["crypto_key_id"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::CryptoKey), request["crypto_key"]
      assert_equal true, request["skip_initial_version_creation"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, create_crypto_key_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.create_crypto_key({ parent: parent, crypto_key_id: crypto_key_id, crypto_key: crypto_key, skip_initial_version_creation: skip_initial_version_creation }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.create_crypto_key parent: parent, crypto_key_id: crypto_key_id, crypto_key: crypto_key, skip_initial_version_creation: skip_initial_version_creation do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.create_crypto_key ::Google::Cloud::Kms::V1::CreateCryptoKeyRequest.new(parent: parent, crypto_key_id: crypto_key_id, crypto_key: crypto_key, skip_initial_version_creation: skip_initial_version_creation) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.create_crypto_key({ parent: parent, crypto_key_id: crypto_key_id, crypto_key: crypto_key, skip_initial_version_creation: skip_initial_version_creation }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.create_crypto_key(::Google::Cloud::Kms::V1::CreateCryptoKeyRequest.new(parent: parent, crypto_key_id: crypto_key_id, crypto_key: crypto_key, skip_initial_version_creation: skip_initial_version_creation), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, create_crypto_key_client_stub.call_rpc_count
    end
  end

  def test_create_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    crypto_key_version = {}

    create_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :create_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::CreateCryptoKeyVersionRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::CryptoKeyVersion), request["crypto_key_version"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, create_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.create_crypto_key_version({ parent: parent, crypto_key_version: crypto_key_version }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.create_crypto_key_version parent: parent, crypto_key_version: crypto_key_version do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.create_crypto_key_version ::Google::Cloud::Kms::V1::CreateCryptoKeyVersionRequest.new(parent: parent, crypto_key_version: crypto_key_version) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.create_crypto_key_version({ parent: parent, crypto_key_version: crypto_key_version }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.create_crypto_key_version(::Google::Cloud::Kms::V1::CreateCryptoKeyVersionRequest.new(parent: parent, crypto_key_version: crypto_key_version), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, create_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_import_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    crypto_key_version = "hello world"
    algorithm = :CRYPTO_KEY_VERSION_ALGORITHM_UNSPECIFIED
    import_job = "hello world"
    rsa_aes_wrapped_key = "hello world"

    import_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :import_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::ImportCryptoKeyVersionRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal "hello world", request["crypto_key_version"]
      assert_equal :CRYPTO_KEY_VERSION_ALGORITHM_UNSPECIFIED, request["algorithm"]
      assert_equal "hello world", request["import_job"]
      assert_equal "hello world", request["rsa_aes_wrapped_key"]
      assert_equal :rsa_aes_wrapped_key, request.wrapped_key_material
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, import_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.import_crypto_key_version({ parent: parent, crypto_key_version: crypto_key_version, algorithm: algorithm, import_job: import_job, rsa_aes_wrapped_key: rsa_aes_wrapped_key }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.import_crypto_key_version parent: parent, crypto_key_version: crypto_key_version, algorithm: algorithm, import_job: import_job, rsa_aes_wrapped_key: rsa_aes_wrapped_key do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.import_crypto_key_version ::Google::Cloud::Kms::V1::ImportCryptoKeyVersionRequest.new(parent: parent, crypto_key_version: crypto_key_version, algorithm: algorithm, import_job: import_job, rsa_aes_wrapped_key: rsa_aes_wrapped_key) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.import_crypto_key_version({ parent: parent, crypto_key_version: crypto_key_version, algorithm: algorithm, import_job: import_job, rsa_aes_wrapped_key: rsa_aes_wrapped_key }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.import_crypto_key_version(::Google::Cloud::Kms::V1::ImportCryptoKeyVersionRequest.new(parent: parent, crypto_key_version: crypto_key_version, algorithm: algorithm, import_job: import_job, rsa_aes_wrapped_key: rsa_aes_wrapped_key), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, import_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_create_import_job
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::ImportJob.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    parent = "hello world"
    import_job_id = "hello world"
    import_job = {}

    create_import_job_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :create_import_job, name
      assert_kind_of ::Google::Cloud::Kms::V1::CreateImportJobRequest, request
      assert_equal "hello world", request["parent"]
      assert_equal "hello world", request["import_job_id"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::ImportJob), request["import_job"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, create_import_job_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.create_import_job({ parent: parent, import_job_id: import_job_id, import_job: import_job }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.create_import_job parent: parent, import_job_id: import_job_id, import_job: import_job do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.create_import_job ::Google::Cloud::Kms::V1::CreateImportJobRequest.new(parent: parent, import_job_id: import_job_id, import_job: import_job) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.create_import_job({ parent: parent, import_job_id: import_job_id, import_job: import_job }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.create_import_job(::Google::Cloud::Kms::V1::CreateImportJobRequest.new(parent: parent, import_job_id: import_job_id, import_job: import_job), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, create_import_job_client_stub.call_rpc_count
    end
  end

  def test_update_crypto_key
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKey.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    crypto_key = {}
    update_mask = {}

    update_crypto_key_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :update_crypto_key, name
      assert_kind_of ::Google::Cloud::Kms::V1::UpdateCryptoKeyRequest, request
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::CryptoKey), request["crypto_key"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::FieldMask), request["update_mask"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, update_crypto_key_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.update_crypto_key({ crypto_key: crypto_key, update_mask: update_mask }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.update_crypto_key crypto_key: crypto_key, update_mask: update_mask do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.update_crypto_key ::Google::Cloud::Kms::V1::UpdateCryptoKeyRequest.new(crypto_key: crypto_key, update_mask: update_mask) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.update_crypto_key({ crypto_key: crypto_key, update_mask: update_mask }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.update_crypto_key(::Google::Cloud::Kms::V1::UpdateCryptoKeyRequest.new(crypto_key: crypto_key, update_mask: update_mask), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, update_crypto_key_client_stub.call_rpc_count
    end
  end

  def test_update_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    crypto_key_version = {}
    update_mask = {}

    update_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :update_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::UpdateCryptoKeyVersionRequest, request
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::CryptoKeyVersion), request["crypto_key_version"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::FieldMask), request["update_mask"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, update_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.update_crypto_key_version({ crypto_key_version: crypto_key_version, update_mask: update_mask }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.update_crypto_key_version crypto_key_version: crypto_key_version, update_mask: update_mask do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.update_crypto_key_version ::Google::Cloud::Kms::V1::UpdateCryptoKeyVersionRequest.new(crypto_key_version: crypto_key_version, update_mask: update_mask) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.update_crypto_key_version({ crypto_key_version: crypto_key_version, update_mask: update_mask }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.update_crypto_key_version(::Google::Cloud::Kms::V1::UpdateCryptoKeyVersionRequest.new(crypto_key_version: crypto_key_version, update_mask: update_mask), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, update_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_update_crypto_key_primary_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKey.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    crypto_key_version_id = "hello world"

    update_crypto_key_primary_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :update_crypto_key_primary_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::UpdateCryptoKeyPrimaryVersionRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["crypto_key_version_id"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, update_crypto_key_primary_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.update_crypto_key_primary_version({ name: name, crypto_key_version_id: crypto_key_version_id }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.update_crypto_key_primary_version name: name, crypto_key_version_id: crypto_key_version_id do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.update_crypto_key_primary_version ::Google::Cloud::Kms::V1::UpdateCryptoKeyPrimaryVersionRequest.new(name: name, crypto_key_version_id: crypto_key_version_id) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.update_crypto_key_primary_version({ name: name, crypto_key_version_id: crypto_key_version_id }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.update_crypto_key_primary_version(::Google::Cloud::Kms::V1::UpdateCryptoKeyPrimaryVersionRequest.new(name: name, crypto_key_version_id: crypto_key_version_id), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, update_crypto_key_primary_version_client_stub.call_rpc_count
    end
  end

  def test_destroy_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    destroy_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :destroy_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::DestroyCryptoKeyVersionRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, destroy_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.destroy_crypto_key_version({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.destroy_crypto_key_version name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.destroy_crypto_key_version ::Google::Cloud::Kms::V1::DestroyCryptoKeyVersionRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.destroy_crypto_key_version({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.destroy_crypto_key_version(::Google::Cloud::Kms::V1::DestroyCryptoKeyVersionRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, destroy_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_restore_crypto_key_version
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::CryptoKeyVersion.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"

    restore_crypto_key_version_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :restore_crypto_key_version, name
      assert_kind_of ::Google::Cloud::Kms::V1::RestoreCryptoKeyVersionRequest, request
      assert_equal "hello world", request["name"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, restore_crypto_key_version_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.restore_crypto_key_version({ name: name }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.restore_crypto_key_version name: name do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.restore_crypto_key_version ::Google::Cloud::Kms::V1::RestoreCryptoKeyVersionRequest.new(name: name) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.restore_crypto_key_version({ name: name }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.restore_crypto_key_version(::Google::Cloud::Kms::V1::RestoreCryptoKeyVersionRequest.new(name: name), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, restore_crypto_key_version_client_stub.call_rpc_count
    end
  end

  def test_encrypt
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::EncryptResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    plaintext = "hello world"
    additional_authenticated_data = "hello world"
    plaintext_crc32c = {}
    additional_authenticated_data_crc32c = {}

    encrypt_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :encrypt, name
      assert_kind_of ::Google::Cloud::Kms::V1::EncryptRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["plaintext"]
      assert_equal "hello world", request["additional_authenticated_data"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["plaintext_crc32c"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["additional_authenticated_data_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, encrypt_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.encrypt({ name: name, plaintext: plaintext, additional_authenticated_data: additional_authenticated_data, plaintext_crc32c: plaintext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.encrypt name: name, plaintext: plaintext, additional_authenticated_data: additional_authenticated_data, plaintext_crc32c: plaintext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.encrypt ::Google::Cloud::Kms::V1::EncryptRequest.new(name: name, plaintext: plaintext, additional_authenticated_data: additional_authenticated_data, plaintext_crc32c: plaintext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.encrypt({ name: name, plaintext: plaintext, additional_authenticated_data: additional_authenticated_data, plaintext_crc32c: plaintext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.encrypt(::Google::Cloud::Kms::V1::EncryptRequest.new(name: name, plaintext: plaintext, additional_authenticated_data: additional_authenticated_data, plaintext_crc32c: plaintext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, encrypt_client_stub.call_rpc_count
    end
  end

  def test_decrypt
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::DecryptResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    ciphertext = "hello world"
    additional_authenticated_data = "hello world"
    ciphertext_crc32c = {}
    additional_authenticated_data_crc32c = {}

    decrypt_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :decrypt, name
      assert_kind_of ::Google::Cloud::Kms::V1::DecryptRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["ciphertext"]
      assert_equal "hello world", request["additional_authenticated_data"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["ciphertext_crc32c"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["additional_authenticated_data_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, decrypt_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.decrypt({ name: name, ciphertext: ciphertext, additional_authenticated_data: additional_authenticated_data, ciphertext_crc32c: ciphertext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.decrypt name: name, ciphertext: ciphertext, additional_authenticated_data: additional_authenticated_data, ciphertext_crc32c: ciphertext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.decrypt ::Google::Cloud::Kms::V1::DecryptRequest.new(name: name, ciphertext: ciphertext, additional_authenticated_data: additional_authenticated_data, ciphertext_crc32c: ciphertext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.decrypt({ name: name, ciphertext: ciphertext, additional_authenticated_data: additional_authenticated_data, ciphertext_crc32c: ciphertext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.decrypt(::Google::Cloud::Kms::V1::DecryptRequest.new(name: name, ciphertext: ciphertext, additional_authenticated_data: additional_authenticated_data, ciphertext_crc32c: ciphertext_crc32c, additional_authenticated_data_crc32c: additional_authenticated_data_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, decrypt_client_stub.call_rpc_count
    end
  end

  def test_asymmetric_sign
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::AsymmetricSignResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    digest = {}
    digest_crc32c = {}
    data = "hello world"
    data_crc32c = {}

    asymmetric_sign_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :asymmetric_sign, name
      assert_kind_of ::Google::Cloud::Kms::V1::AsymmetricSignRequest, request
      assert_equal "hello world", request["name"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Kms::V1::Digest), request["digest"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["digest_crc32c"]
      assert_equal "hello world", request["data"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["data_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, asymmetric_sign_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.asymmetric_sign({ name: name, digest: digest, digest_crc32c: digest_crc32c, data: data, data_crc32c: data_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.asymmetric_sign name: name, digest: digest, digest_crc32c: digest_crc32c, data: data, data_crc32c: data_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.asymmetric_sign ::Google::Cloud::Kms::V1::AsymmetricSignRequest.new(name: name, digest: digest, digest_crc32c: digest_crc32c, data: data, data_crc32c: data_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.asymmetric_sign({ name: name, digest: digest, digest_crc32c: digest_crc32c, data: data, data_crc32c: data_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.asymmetric_sign(::Google::Cloud::Kms::V1::AsymmetricSignRequest.new(name: name, digest: digest, digest_crc32c: digest_crc32c, data: data, data_crc32c: data_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, asymmetric_sign_client_stub.call_rpc_count
    end
  end

  def test_asymmetric_decrypt
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::AsymmetricDecryptResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    ciphertext = "hello world"
    ciphertext_crc32c = {}

    asymmetric_decrypt_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :asymmetric_decrypt, name
      assert_kind_of ::Google::Cloud::Kms::V1::AsymmetricDecryptRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["ciphertext"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["ciphertext_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, asymmetric_decrypt_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.asymmetric_decrypt({ name: name, ciphertext: ciphertext, ciphertext_crc32c: ciphertext_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.asymmetric_decrypt name: name, ciphertext: ciphertext, ciphertext_crc32c: ciphertext_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.asymmetric_decrypt ::Google::Cloud::Kms::V1::AsymmetricDecryptRequest.new(name: name, ciphertext: ciphertext, ciphertext_crc32c: ciphertext_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.asymmetric_decrypt({ name: name, ciphertext: ciphertext, ciphertext_crc32c: ciphertext_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.asymmetric_decrypt(::Google::Cloud::Kms::V1::AsymmetricDecryptRequest.new(name: name, ciphertext: ciphertext, ciphertext_crc32c: ciphertext_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, asymmetric_decrypt_client_stub.call_rpc_count
    end
  end

  def test_mac_sign
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::MacSignResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    data = "hello world"
    data_crc32c = {}

    mac_sign_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :mac_sign, name
      assert_kind_of ::Google::Cloud::Kms::V1::MacSignRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["data"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["data_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, mac_sign_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.mac_sign({ name: name, data: data, data_crc32c: data_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.mac_sign name: name, data: data, data_crc32c: data_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.mac_sign ::Google::Cloud::Kms::V1::MacSignRequest.new(name: name, data: data, data_crc32c: data_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.mac_sign({ name: name, data: data, data_crc32c: data_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.mac_sign(::Google::Cloud::Kms::V1::MacSignRequest.new(name: name, data: data, data_crc32c: data_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, mac_sign_client_stub.call_rpc_count
    end
  end

  def test_mac_verify
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::MacVerifyResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    name = "hello world"
    data = "hello world"
    data_crc32c = {}
    mac = "hello world"
    mac_crc32c = {}

    mac_verify_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :mac_verify, name
      assert_kind_of ::Google::Cloud::Kms::V1::MacVerifyRequest, request
      assert_equal "hello world", request["name"]
      assert_equal "hello world", request["data"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["data_crc32c"]
      assert_equal "hello world", request["mac"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Protobuf::Int64Value), request["mac_crc32c"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, mac_verify_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.mac_verify({ name: name, data: data, data_crc32c: data_crc32c, mac: mac, mac_crc32c: mac_crc32c }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.mac_verify name: name, data: data, data_crc32c: data_crc32c, mac: mac, mac_crc32c: mac_crc32c do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.mac_verify ::Google::Cloud::Kms::V1::MacVerifyRequest.new(name: name, data: data, data_crc32c: data_crc32c, mac: mac, mac_crc32c: mac_crc32c) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.mac_verify({ name: name, data: data, data_crc32c: data_crc32c, mac: mac, mac_crc32c: mac_crc32c }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.mac_verify(::Google::Cloud::Kms::V1::MacVerifyRequest.new(name: name, data: data, data_crc32c: data_crc32c, mac: mac, mac_crc32c: mac_crc32c), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, mac_verify_client_stub.call_rpc_count
    end
  end

  def test_generate_random_bytes
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Kms::V1::GenerateRandomBytesResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    location = "hello world"
    length_bytes = 42
    protection_level = :PROTECTION_LEVEL_UNSPECIFIED

    generate_random_bytes_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :generate_random_bytes, name
      assert_kind_of ::Google::Cloud::Kms::V1::GenerateRandomBytesRequest, request
      assert_equal "hello world", request["location"]
      assert_equal 42, request["length_bytes"]
      assert_equal :PROTECTION_LEVEL_UNSPECIFIED, request["protection_level"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, generate_random_bytes_client_stub do
      # Create client
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.generate_random_bytes({ location: location, length_bytes: length_bytes, protection_level: protection_level }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.generate_random_bytes location: location, length_bytes: length_bytes, protection_level: protection_level do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.generate_random_bytes ::Google::Cloud::Kms::V1::GenerateRandomBytesRequest.new(location: location, length_bytes: length_bytes, protection_level: protection_level) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.generate_random_bytes({ location: location, length_bytes: length_bytes, protection_level: protection_level }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.generate_random_bytes(::Google::Cloud::Kms::V1::GenerateRandomBytesRequest.new(location: location, length_bytes: length_bytes, protection_level: protection_level), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, generate_random_bytes_client_stub.call_rpc_count
    end
  end

  def test_configure
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure

    client = block_config = config = nil
    Gapic::ServiceStub.stub :new, nil do
      client = ::Google::Cloud::Kms::V1::KeyManagementService::Client.new do |config|
        config.credentials = grpc_channel
      end
    end

    config = client.configure do |c|
      block_config = c
    end

    assert_same block_config, config
    assert_kind_of ::Google::Cloud::Kms::V1::KeyManagementService::Client::Configuration, config
  end
end


text:
package com.dalimao.library.util;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import static android.os.Environment.MEDIA_MOUNTED;

/**
 * Created by liuguangli on 15/12/17.
 */
public class DeviceInfoUtil {
    private static final String EXTERNAL_STORAGE_PERMISSION = "android.permission.WRITE_EXTERNAL_STORAGE";

    public static final int PORTRAIT = 1;
    public static final int LANDSCAPE = 2;
    private static final String TAG = "DeviceInfoUtil";
    private static  DisplayMetrics displayMetrics;
    private static String sExternalSdCardPath = null;
    private static String imei = "";

    private static String imsi = "";
    private static String exSdCardPath = "";
    public static DisplayMetrics getScreenSize(Context context){
        if (displayMetrics == null){
            try {

                displayMetrics = new DisplayMetrics();
                displayMetrics.widthPixels = 1280;
                displayMetrics.heightPixels = 720;
                WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                wm.getDefaultDisplay().getMetrics(displayMetrics);
            } catch (Exception e){
                Log.e(TAG,e.getMessage());
            }

        }
        return displayMetrics;
    }

    public static float getDesity(Context context){
        getScreenSize(context);
        return displayMetrics.density;
    }

    public static int getScreenLongSize(Context context){
        getScreenSize(context);
        return Math.max(displayMetrics.widthPixels, displayMetrics.heightPixels);
    }
    public static int getScreenShortSize(Context context){
        getScreenSize(context);
        return Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
    }
    public static int getOrientation(Context context){
        DisplayMetrics displayMetrics = new DisplayMetrics();
        displayMetrics.widthPixels = 1280;
        displayMetrics.heightPixels = 720;
        try {
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            wm.getDefaultDisplay().getMetrics(displayMetrics);
        } catch (Exception e){
            //do nothing
        }

        if (displayMetrics.heightPixels>displayMetrics.widthPixels){
            return PORTRAIT;
        } else {
            return LANDSCAPE;
        }
    }
    /**
     * @return
     */
    public static int getSystemVersion(){

        return Build.VERSION.SDK_INT;
    }
    /**
     */
    public static String getBuildModel(){

        return Build.MANUFACTURER+Build.MODEL;
    }

    /**
     * @param context 获取sd卡路径
     * @return
     */
    public static String getExternalSDCardPath(Context context) {
        // ArrayList<String> paths = (ArrayList<String>) getExtSDCardPaths();
        // if (paths.size() != 0)
        // return paths.get(0) + "/";
        if (sExternalSdCardPath != null)
            return sExternalSdCardPath;
        String externalStorageState;
        File externalDir = null;// 获取手机根目录
        try {
            externalStorageState = Environment.getExternalStorageState();
        } catch (NullPointerException e) { // (sh)it happens (Issue #660)
            externalStorageState = "";
        }
        if (MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
            externalDir = Environment.getExternalStorageDirectory();
        }
        String path = null;
        if (externalDir == null || !externalDir.exists() || !externalDir.canWrite()) {
            externalDir = context.getCacheDir();
            if (externalDir != null) {
                path = externalDir.getPath();
                path = path.endsWith("/") ? path : path + "/";
                sExternalSdCardPath = path;
            }
        } else {
            path = externalDir.getPath();
            path = path.endsWith("/") ? path : path + "/";
            sExternalSdCardPath = path;
        }
        // 如果还为空
//         fix 静态代码扫描 zhengyx 2016.03.15
        if (TextUtils.isEmpty(sExternalSdCardPath)) {
            String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
            sExternalSdCardPath = cacheDirPath;
        }
        Log.d(TAG, "sExternalSdCardPath=" + sExternalSdCardPath);
        return sExternalSdCardPath;
    }
    private static boolean hasExternalStoragePermission(Context context) {
        int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
        return perm == PackageManager.PERMISSION_GRANTED;
    }

    public static String getDeviceType(Context context) {
        String phoneString = Build.MODEL;
        return phoneString;
    }

    public static String getSystemVersionRelease() {
        String systemVersion = Build.VERSION.RELEASE;
        return systemVersion;
    }

    public static String getLocalMacAddress(Context context) {
        if (context == null) {
            return null;
        }
        //1.9.2 bigfix NullPointerException 防止由于某些系统getSystemService不稳定导致activityManager为null情况
        try {
            WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo info = wifi.getConnectionInfo();
            return info.getMacAddress();
        }catch (RuntimeException e) {
            Log.e(TAG, e.getMessage());
        }
        return null;
    }

    public static String getIMSI(Context context) {
        if(context == null){
            return null;
        }
        if(TextUtils.isEmpty(imsi)) {
            TelephonyManager mTelephonyMgr = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            try { //Android 6.0异常捕获
                imsi = mTelephonyMgr.getSubscriberId();
            }catch (SecurityException e){
                Log.e(TAG,e.getMessage());
            }
        }
        return imsi;
    }

    public static String getIMEI(Context context) {
        if (context == null) {
            return null;
        }
        if(TextUtils.isEmpty(imei)) {
            TelephonyManager tm = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            try {  //Android 6.0异常捕获
                imei = tm.getDeviceId();
            }catch (SecurityException e){
                Log.e(TAG,e.getMessage());
            }
        }
        return imei;
    }
    /**
     * 获得外部sdcard存储位置
     *
     * @return
     * @author tiandp 2015-5-28
     */
    public static List<String> getExtSDCardPaths() {
        List<String> paths = new ArrayList<String>();
        String extFileStatus = Environment.getExternalStorageState();
        File extFile = Environment.getExternalStorageDirectory();
        if (extFileStatus.endsWith(Environment.MEDIA_UNMOUNTED) && extFile.exists()
                && extFile.isDirectory() && extFile.canWrite()) {
            paths.add(extFile.getAbsolutePath());
        }
        try {
            // obtain executed result of command line code of 'mount', to judge
            // whether tfCard exists by the result
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec("mount");
            InputStream is = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            int mountPathIndex = 1;
            while ((line = br.readLine()) != null) {
                // format of sdcard file system: vfat/fuse
                if ((!line.contains("fat") && !line.contains("fuse") && !line.contains("storage"))
                        || line.contains("secure") || line.contains("asec")
                        || line.contains("firmware") || line.contains("shell")
                        || line.contains("obb") || line.contains("legacy") || line.contains("data")) {
                    continue;
                }
                String[] parts = line.split(" ");
                int length = parts.length;
                if (mountPathIndex >= length) {
                    continue;
                }
                String mountPath = parts[mountPathIndex];
                if (!mountPath.contains("/") || mountPath.contains("data")
                        || mountPath.contains("Data")) {
                    continue;
                }
                File mountRoot = new File(mountPath);
                if (!mountRoot.exists() || !mountRoot.isDirectory() || !mountRoot.canWrite()) {
                    continue;
                }
                boolean equalsToPrimarySD = mountPath.equals(extFile.getAbsolutePath());
                if (equalsToPrimarySD) {
                    continue;
                }
                paths.add(mountPath);
            }
        } catch (IOException e) {
            Log.e(TAG, "IOException:" + e.getMessage());
        }
        return paths;
    }
    public static String getExSdCardPath() {
        if("".equals(exSdCardPath)){
            ArrayList<String> paths = (ArrayList<String>) getExtSDCardPaths();
            if (paths.size() != 0) {
                exSdCardPath = paths.get(0) + "/";
            }else{
                exSdCardPath = null;
            }
        }

        return exSdCardPath;
    }
    /****************************** pushconfig *********************************************/
    /**
     * 分辨率
     *
     * @param
     * @param
     * @return
     * @exception/throws
     * @see
     */
    public static Point getScreenPixed(Context context) {
        if (context == null) return null;
        if (displayMetrics == null){
             displayMetrics = context.getResources().getDisplayMetrics();
        }
        Point point = new Point();

        point.x = displayMetrics.widthPixels;
        point.y = displayMetrics.heightPixels;
        return point;
    }

    public static String getCpuInfno() {
        String arch = "";// cpu类型
        try {
            Class<?> clazz = Class.forName("android.os.SystemProperties");
            Method get = clazz.getDeclaredMethod("get", new Class[]{
                    String.class
            });
            arch = (String) get.invoke(clazz, new Object[]{
                    "ro.product.cpu.abi"
            });
        } catch (Exception e) {
            Log.e(TAG,e.getMessage());
        }
        return arch;
    }

    public static long getFreeMemory(Context context) {

        // 获取android当前可用内存大小
        long fm = 0;
        try {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
            am.getMemoryInfo(mi);
            fm = mi.availMem/(1024*1024);
        } catch (Exception e) {

        }

        return fm;
    }

    public static String getSmsNo(Context context) {
        //获取手机号码

        String tel  = null;
        try {
            TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            tel =  tm.getLine1Number();//获取本机号码
        } catch (Exception e) {

        }
        return tel;
    }
}

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Custom Callback</title>

    <link href="../dist/css/ngplacesmap.min.css" media="all" rel="stylesheet" />

Custom Callback

    <places-map custom-callback="customCallbackFunction( pickedPlace )"></places-map>


text:
@interface PodsDummy_Pods_DataSources_Tests : NSObject
@end
@implementation PodsDummy_Pods_DataSources_Tests
@end


text:
<?php

namespace artkost\attachment\behaviors;

use artkost\attachment\Manager;
use artkost\attachment\models\AttachmentFile;
use Yii;
use yii\base\Behavior;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\db\ActiveQuery;
use yii\db\ActiveQueryInterface;
use yii\db\ActiveRecord;
use yii\helpers\Html;

/**
 * Class AttachBehavior
 * @package artkost\attachment
 * Attachment file behavior.
 *
 * @property ActiveRecord $owner
 */
class AttachBehavior extends Behavior
{
    /**
     * Are available 3 indexes:
     * - `path` Path where the file will be moved.
     * - `tempPath` Temporary path from where file will be moved.
     * - `url` Path URL where file will be saved.
     *
     * @var array Models instance config
     */
    public $models = [];

    /**
     * @inheritdoc
     */
    public function attach($owner)
    {
        parent::attach($owner);

        if (!is_array($this->models) || empty($this->models)) {
            throw new InvalidParamException('Invalid or empty models array.');
        } else {
            foreach ($this->models as $relationName => $config) {
                Manager::getInstance()->addAttachmentModel($this->owner, $relationName, $config);

                $this->checkRelationExistence($relationName);
            }
        }
    }

    /**
     * @inheritdoc
     */
    public function events()
    {
        return [
            ActiveRecord::EVENT_BEFORE_INSERT => 'beforeInsert',
            ActiveRecord::EVENT_BEFORE_UPDATE => 'beforeUpdate',
            ActiveRecord::EVENT_BEFORE_DELETE => 'beforeDelete'
        ];
    }

    /**
     * @param $attribute
     * @return null|array
     */
    public function getAttachmentConfig($attribute)
    {
        return isset($this->models[$attribute]) ? $this->models[$attribute] : null;
    }

    /**
     * @param string $name
     * @return mixed|null
     */
    protected function getRelationValues($name)
    {
        return Html::getAttributeValue($this->owner, $name);
    }

    /**
     * @param int|array $values
     * @return bool|int
     */
    protected function deleteFiles($values)
    {
        return AttachmentFile::deleteAll(['id' => $values]);
    }

    /**
     * @param int|array $values
     * @return bool
     */
    protected function markFilesAsPermanent($values)
    {
        return AttachmentFile::updateAll([
            'status_id' => AttachmentFile::STATUS_PERMANENT
        ], ['id' => $values]);
    }

    /**
     * @param int|array $values
     * @return bool
     */
    protected function markFilesAsTemporary($values)
    {
        return AttachmentFile::updateAll([
            'status_id' => AttachmentFile::STATUS_TEMPORARY
        ], ['id' => $values]);
    }

    /**
     * Check if relation with given name exists in model
     * @param $name
     * @throws InvalidConfigException
     */
    protected function checkRelationExistence($name)
    {
        $getter = 'get' . ucfirst($name);
        $class = get_class($this->owner);

        if (method_exists($this->owner, $getter)) {
            /** @var ActiveQuery $value */
            $value = $this->owner->$getter();

            if (!($value instanceof ActiveQueryInterface)) {
                throw new InvalidConfigException("Value of relation '$getter' not valid");
            }

            $this->models[$name]['multiple'] = $value->multiple;
        } else {
            throw new InvalidConfigException("Relation '$class::$getter' for attribute '$name' does not exists");
        }
    }

    /**
     * Helper method for define attachment relations
     * @param $class
     * @param $link
     * @param bool $status
     * @return static
     */
    public function hasOneAttachment($class, $link, $status = false)
    {
        return $this->owner->hasOne($class, $link)
            ->andWhere(['type' => $class::type(), 'status_id' => $class::STATUS_PERMANENT]);
    }

    /**
     * Helper method for define attachment relations
     * @param $class
     * @param $link
     * @param bool $status
     * @return static
     */
    public function hasManyAttachments($class, $link, $status = false)
    {
        return $this->owner->hasMany($class, $link)
            ->andWhere(['type' => $class::type(), 'status_id' => $class::STATUS_PERMANENT]);
    }

    /**
     *
     */
    public function beforeInsert()
    {
        foreach ($this->models as $relationName => $config) {
            $this->markFilesAsPermanent($this->getRelationValues($relationName));
        }
    }

    /**
     * Function will be called before updating the record.
     */
    public function beforeUpdate()
    {
        foreach ($this->models as $relationName => $config) {
            $this->markFilesAsPermanent($this->getRelationValues($relationName));
        }
    }

    /**
     * Function will be called before deleting the record.
     */
    public function beforeDelete()
    {
        foreach ($this->models as $relationName => $config) {
            $this->deleteFiles($config);
        }
    }
}


text:
/** @suppress{duplicate} */
var mylib = mylib || require('./mylib');

describe('mylib', function() {
  it('adds six', function() {
    expect(mylib.publicAddSix(5)).toBe(11);
  });
});


text:
package honux;

public class Lion  <T>{
	public Lion(double weight) {
		this.weight = weight;
	}
	public double weight;
	public void eat(T t) {
		if (t instanceof Student ) {
			weight += ((Student) t).weight / 10;
			System.out.println("I like human and my weight is now " + weight);

		}
		else {
			System.out.println("I don't like " + t.getClass().getName());
		}
	}
}


text:
@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (weak, nonatomic) IBOutlet UIButton *scanButton;

@property (weak, nonatomic) IBOutlet UILabel *scanLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

// 扫码
- (IBAction)scanQRCode {
    LYQRCodeViewController *qrcoderVC = [[LYQRCodeViewController alloc] init];

    // 扫码成功
    qrcoderVC.LYQRCodeSuncessBlock = ^(LYQRCodeViewController *aqrvc, NSString *qrString){
        self.scanLabel.text = qrString;
        [aqrvc dismissViewControllerAnimated:NO completion:nil];
    };

    // 扫码失败
    qrcoderVC.LYQRCodeFailBlock = ^(LYQRCodeViewController *aqrvc){
        self.scanLabel.text = @"扫描失败...";
        [aqrvc dismissViewControllerAnimated:NO completion:nil];
    };

    // 扫码取消
    qrcoderVC.LYQRCodeCancleBlock = ^(LYQRCodeViewController *aqrvc){
        [aqrvc dismissViewControllerAnimated:NO completion:nil];
        self.scanLabel.text = @"扫码取消...";
    };

    [self presentViewController:qrcoderVC animated:YES completion:nil];
}
- (IBAction)readQRCode:(id)sender {
    // 选择照片
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"请选择操作" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    // 判断是否支持相机
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            imagePicker.allowsEditing = YES;
            imagePicker.delegate = self;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }]];
        [alertController addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.allowsEditing = YES;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }]];
    } else {
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            imagePicker.allowsEditing = YES;
            imagePicker.delegate = self;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }]];
    }

    UIAlertAction *canelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:canelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    // 获取的图片
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    self.scanLabel.text = [LYQRCodeUtil readQRCodeFromImage:image];

    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end


text:
const express = require('express');
const mongodb = require('mongodb').MongoClient;
const objectId = require('mongodb').ObjectID;

const url = 'mongodb://localhost:27017/libraryApp';
const booksRouter = express.Router();

booksRouter.route('/')
    .get((req, res) => {

        mongodb.connect(url, (err, db) => {
            var collection = db.collection('books');
            collection.find().toArray((err, results)=>{
                res.render('books', {layout: false, title: 'Books', books: results});
            });
        });
    });

booksRouter.route('/:id')
    .get((req, res) => {
        var id = new objectId(req.params.id);
        console.log(id);
        mongodb.connect(url, (err, db) => {
            var collection = db.collection('books');
            var result = collection.findOne({_id: id}, (err, result) => {
                console.log(result);
                res.render('books', { layout: false, title: result.title });
            });
        });

    });

module.exports = booksRouter;


text:
goog.provide('lf.proc.CrossProductStep');

goog.require('goog.Promise');
goog.require('goog.asserts');
goog.require('lf.proc.PhysicalQueryPlanNode');
goog.require('lf.proc.Relation');
goog.require('lf.proc.RelationEntry');

/**
 * @constructor @struct
 * @extends {lf.proc.PhysicalQueryPlanNode}
 */
lf.proc.CrossProductStep = function() {
  lf.proc.CrossProductStep.base(this, 'constructor');
};
goog.inherits(lf.proc.CrossProductStep, lf.proc.PhysicalQueryPlanNode);

/** @override */
lf.proc.CrossProductStep.prototype.toString = function() {
  return 'cross_product';
};

/** @override */
lf.proc.CrossProductStep.prototype.exec = function(tx) {
  goog.asserts.assert(
      this.getChildCount() == 2,
      'Only cross-products of 2 relations are currently supported.');
  var promises = this.getChildren().map(function(child) {
    return child.exec(tx);
  });

  return goog.Promise.all(promises).then(goog.bind(
      /**
       * @param {!Array.<!lf.proc.Relation>} results
       * @return {!lf.proc.Relation}
       */
      function(results) {
        return lf.proc.CrossProductStep.crossProduct_(results[0], results[1]);
      }, this));
};

/**
 * Calculates the cross product of two relations.
 * @param {!lf.proc.Relation} leftRelation The first relation.
 * @param {!lf.proc.Relation} rightRelation The second relation.
 * @return {!lf.proc.Relation} The combined relation.
 * @private
 */
lf.proc.CrossProductStep.crossProduct_ = function(
    leftRelation, rightRelation) {
  var combinedEntries = [];

  var leftRelationTableNames = leftRelation.getTables();
  var rightRelationTableNames = rightRelation.getTables();
  for (var i = 0; i < leftRelation.entries.length; i++) {
    for (var j = 0; j < rightRelation.entries.length; j++) {
      var combinedEntry = lf.proc.RelationEntry.combineEntries(
          leftRelation.entries[i], leftRelationTableNames,
          rightRelation.entries[j], rightRelationTableNames);
      combinedEntries.push(combinedEntry);
    }
  }

  var srcTables = leftRelation.getTables().concat(rightRelation.getTables());
  return new lf.proc.Relation(combinedEntries, srcTables);
};


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Acta Mycologica, Warszawa 25(1): 50 (1990)

#### Original name
Stigmatomyces biformis T. Majewski, 1990

### Remarks
null