     email = new_email(from: %{foo: :bar})
 
     assert_raise ArgumentError, fn ->
-      FooMailer.deliver_now(email)
+      Mailer.deliver_now(email)
     end
   end
 


    assert_raise RuntimeError, ~r/cannot call Bamboo.Mailer/, fn ->
      Bamboo.Mailer.deliver_later(email)
    end
  end


    assert delivered_email.bcc == [converted_recipient]
  end

  test "deliver_later/1 calls deliver on the adapter" do
    email = new_email()

    Mailer.deliver_later(email)

    assert_receive {:deliver, delivered_email, _config}
    assert delivered_email == Bamboo.Mailer.normalize_addresses(email)
  end

  test "deliver_now/1 wraps the recipients in a list" do
    address = {"Someone", "foo@bar.com"}
    email = new_email(to: address, cc: address, bcc: address)

    Mailer.deliver_now(email)

    assert_received {:deliver, delivered_email, _}
    assert delivered_email.to == [address]
    assert delivered_email.cc == [address]
    assert delivered_email.bcc == [address]
  end

  test "sets a default deliver_later_strategy if none is set" do
    email = new_email(to: "foo@bar.com")

    Mailer.deliver_now(email)

    assert_received {:deliver, _email, config}
    assert config.deliver_later_strategy == Bamboo.TaskSupervisorStrategy
  end

  test "deliver_now/1 calls the adapter with the email and config as a map" do
    email = new_email(to: "foo@bar.com")

    expected_final_config =
      @mailer_config
      |> Enum.into(%{})
      |> Map.put(:deliver_later_strategy, Bamboo.TaskSupervisorStrategy)

    returned_email = Mailer.deliver_now(email)

    assert returned_email == Bamboo.Mailer.normalize_addresses(email)
    assert_received {:deliver, %Bamboo.Email{}, ^expected_final_config}
  end

  test "deliver/1 raises a helpful error message" do
    assert_raise RuntimeError, ~r/Use deliver_now/, fn ->
      Mailer.deliver(:anything)
    end
  end

  test "deliver_now/1 with no from address raises an error" do
    assert_raise Bamboo.EmptyFromAddressError, fn ->
      Mailer.deliver_now(new_email(from: nil))
    end

    assert_raise Bamboo.EmptyFromAddressError, fn ->
      Mailer.deliver_now(new_email(from: {"foo", nil}))
    end
  end

  test "deliver_now/1 with empty lists for recipients does not deliver email" do
    new_email(to: [], cc: [], bcc: []) |> Mailer.deliver_now()
    refute_received {:deliver, _, _}

    new_email(to: [], cc: nil, bcc: nil) |> Mailer.deliver_now()
    refute_received {:deliver, _, _}

    new_email(to: nil, cc: [], bcc: nil) |> Mailer.deliver_now()
    refute_received {:deliver, _, _}

    new_email(to: nil, cc: nil, bcc: []) |> Mailer.deliver_now()
    refute_received {:deliver, _, _}
  end

  test "deliver_later/1 with empty lists for recipients does not deliver email" do
    new_email(to: [], cc: [], bcc: []) |> Mailer.deliver_later()
    refute_received {:deliver, _, _}

    new_email(to: [], cc: nil, bcc: nil) |> Mailer.deliver_later()
    refute_received {:deliver, _, _}

    new_email(to: nil, cc: [], bcc: nil) |> Mailer.deliver_later()
    refute_received {:deliver, _, _}

    new_email(to: nil, cc: nil, bcc: []) |> Mailer.deliver_later()
    refute_received {:deliver, _, _}
  end

  test "raises an error if an address does not have a protocol implemented" do
    email = new_email(from: 1)

    assert_raise Protocol.UndefinedError, fn ->
      Mailer.deliver_now(email)
    end
  end

  test "raises if all recipients are nil" do
    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: nil, cc: nil, bcc: nil)
      |> Mailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: {"foo", nil})
      |> Mailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: [{"foo", nil}])
      |> Mailer.deliver_now()
    end

    assert_raise Bamboo.NilRecipientsError, fn ->
      new_email(to: [nil])
      |> Mailer.deliver_now()
    end
  end

