/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.sync;

import org.mozilla.gecko.fxa.login.Married;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.fxa.login.State.StateLabel;

/**
 * A collection of functions for operating on a FirefoxAccount.
 */
public class FirefoxAccountUtils {
    private FirefoxAccountUtils() {}

    public static boolean isMarried(final State accountState) {
        return accountState.getStateLabel() == StateLabel.Married;
    }

    /**
     * Asserts Married and returns the account state casted to Married.
     *
     * @return the given account state casted to {@link Married}.
     * @throws IllegalArgumentException if the account is not in the Married state.
     */
    public static Married getMarried(final State accountState) {
        if (!isMarried(accountState)) {
            throw new IllegalArgumentException("Expected account to be married.");
        }
        return (Married) accountState;
    }
}

@@ -237,138 +237,572 @@
 ort 
-org.mozilla.gecko.fxa.login.Married;%0Aimport org.mozilla.gecko.fxa.login.State;%0Aimport org.mozilla.gecko.fxa.login.State.StateLabel
+android.support.annotation.WorkerThread;%0Aimport org.mozilla.gecko.background.fxa.FxAccountClient;%0Aimport org.mozilla.gecko.browserid.BrowserIDKeyPair;%0Aimport org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine;%0Aimport org.mozilla.gecko.fxa.login.FxAccountLoginTransition;%0Aimport org.mozilla.gecko.fxa.login.Married;%0Aimport org.mozilla.gecko.fxa.login.State;%0Aimport org.mozilla.gecko.fxa.login.State.StateLabel;%0Aimport org.mozilla.sync.login.FirefoxAccountLoginDefaultDelegate;%0A%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.util.concurrent.Executor
 ;%0A%0A/
@@ -1570,11 +1570,1000 @@
 e;%0A    %7D
+%0A%0A    public static void advanceAccountToMarried(final FirefoxAccount firefoxAccount, final Executor backgroundExecutor, final MarriedLoginCallback callback) %7B%0A        backgroundExecutor.execute(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                new FxAccountLoginStateMachine().advance(firefoxAccount.accountState, StateLabel.Married, new FirefoxAccountLoginDefaultDelegate(firefoxAccount, backgroundExecutor) %7B%0A                    @Override%0A                    public void handleFinal(final State state) %7B%0A                        if (isMarried(state)) %7B%0A                            callback.onMarried(getMarried(state));%0A                        %7D else %7B%0A                            callback.onNotMarried(state);%0A                        %7D%0A                    %7D%0A                %7D);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    interface MarriedLoginCallback %7B%0A        void onMarried(Married marriedState);%0A        void onNotMarried(State notMarriedState);%0A    %7D
 %0A%7D%0A

Add FirefoxAccountUtils.advanceAccountToMarried.