<commit_before>/*
 * Copyright 2018 mk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mk.gdx.firebase.ios.auth;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.internal.verification.VerificationModeFactory;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.moe.natj.general.NatJ;
import org.moe.natj.general.ptr.Ptr;
import org.moe.natj.general.ptr.impl.PtrFactory;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import apple.foundation.NSError;
import apple.foundation.NSURL;
import bindings.google.firebaseauth.FIRAuth;
import bindings.google.firebaseauth.FIRUser;
import mk.gdx.firebase.auth.GdxFirebaseUser;
import mk.gdx.firebase.callbacks.AuthCallback;
import mk.gdx.firebase.callbacks.SignOutCallback;
import mk.gdx.firebase.ios.GdxIOSAppTest;

@PrepareForTest({NatJ.class, FIRAuth.class, FIRUser.class, NSURL.class, NSError.class, PtrFactory.class, Ptr.class})
public class AuthTest extends GdxIOSAppTest {

    private FIRAuth firAuth;

    @Override
    public void setup() {
        super.setup();
        PowerMockito.mockStatic(FIRAuth.class);
        PowerMockito.mockStatic(FIRUser.class);
        PowerMockito.mockStatic(PtrFactory.class);
        PowerMockito.mockStatic(NSError.class);
        PowerMockito.mockStatic(Ptr.class);
        PowerMockito.mockStatic(NSURL.class);
        firAuth = PowerMockito.mock(FIRAuth.class);
        Mockito.when(FIRAuth.auth()).thenReturn(firAuth);
    }

    @Test
    public void getCurrentUser() {
        // Given
        FIRUser firUser = Mockito.mock(FIRUser.class);
        NSURL nsurl = Mockito.mock(NSURL.class);
        Mockito.when(nsurl.path()).thenReturn("test");
        Mockito.when(firAuth.currentUser()).thenReturn(firUser);
        Mockito.when(firUser.displayName()).thenReturn("display_name");
        Mockito.when(firUser.email()).thenReturn("email");
        Mockito.when(firUser.photoURL()).thenReturn(nsurl);
        Mockito.when(firUser.uid()).thenReturn("uid");
        Mockito.when(firUser.isAnonymous()).thenReturn(true);
        Mockito.when(firUser.isEmailVerified()).thenReturn(false);
        Auth auth = new Auth();

        // When
        GdxFirebaseUser gdxFirebaseUser = auth.getCurrentUser();

        // Then
        Assert.assertNotNull(gdxFirebaseUser);
        Assert.assertNotNull(gdxFirebaseUser.getUserInfo());
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().getDisplayName(), "display_name");
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().getEmail(), "email");
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().getPhotoUrl(), "test");
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().getUid(), "uid");
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().isAnonymous(), true);
        Assert.assertEquals(gdxFirebaseUser.getUserInfo().isEmailVerified(), false);
    }

    @Test
    public void createUserWithEmailAndPassword() {
        // Given
        AuthCallback callback = Mockito.mock(AuthCallback.class);
        Mockito.doAnswer(new Answer() {
            @Override<commit_msg>iOS: auth unit tests refactoring<commit_after>/*
 * Copyright 2018 mk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mk.gdx.firebase.ios.auth;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.verification.VerificationModeFactory;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.moe.natj.general.NatJ;
import org.moe.natj.general.ptr.Ptr;
import org.moe.natj.general.ptr.impl.PtrFactory;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;

import apple.foundation.NSError;
import apple.foundation.NSURL;
import bindings.google.firebaseauth.FIRAuth;
import bindings.google.firebaseauth.FIRUser;
import mk.gdx.firebase.auth.GdxFirebaseUser;
import mk.gdx.firebase.callbacks.AuthCallback;
import mk.gdx.firebase.callbacks.SignOutCallback;
import mk.gdx.firebase.ios.GdxIOSAppTest;

@PrepareForTest({NatJ.class, FIRAuth.class, FIRUser.class, NSURL.class, NSError.class, PtrFactory.class, Ptr.class})
public class AuthTest extends GdxIOSAppTest {

    private FIRAuth firAuth;

    @Override
    public void setup() {
        super.setup();
        PowerMockito.mockStatic(FIRAuth.class);
        PowerMockito.mockStatic(FIRUser.class);
        PowerMockito.mockStatic(PtrFactory.class);
        PowerMockito.mockStatic(NSError.class);
        PowerMockito.mockStatic(Ptr.class);
        PowerMockito.mockStatic(NSURL.class);
        firAuth = PowerMockito.mock(FIRAuth.class);
        Mockito.when(FIRAuth.auth()).thenReturn(firAuth);
    }

    @Test
    public void getCurrentUser() {
        // Given
        FIRUser firUser = Mockito.mock(FIRUser.class);
        NSURL nsurl = Mockito.mock(NSURL.class);
        Mockito.when(nsurl.path()).thenReturn("test");
        Mockito.when(firAuth.currentUser()).thenReturn(firUser);
        Mockito.when(firUser.displayName()).thenReturn("display_name");
        Mockito.when(firUser.email()).thenReturn("email");
        Mockito.when(firUser.photoURL()).thenReturn(nsurl);
        Mockito.when(firUser.uid()).thenReturn("uid");
        Mockito.when(firUser.isAnonymous()).thenReturn(true);
        Mockito.when(firUser.isEmailVerified()).thenReturn(false);
        Auth auth = new Auth();

        // When
        GdxFirebaseUser gdxFirebaseUser = auth.getCurrentUser();

        // Then
        Assert.assertNotNull(gdxFirebaseUser);
        Assert.assertNotNull(gdxFirebaseUser.getUserInfo());
        Assert.assertEquals("display_name", gdxFirebaseUser.getUserInfo().getDisplayName());
        Assert.assertEquals("email", gdxFirebaseUser.getUserInfo().getEmail());
        Assert.assertEquals("test", gdxFirebaseUser.getUserInfo().getPhotoUrl());
        Assert.assertEquals("uid", gdxFirebaseUser.getUserInfo().getUid());
        Assert.assertEquals(true, gdxFirebaseUser.getUserInfo().isAnonymous());
        Assert.assertEquals(false, gdxFirebaseUser.getUserInfo().isEmailVerified());
    }

    @Test
    public void createUserWithEmailAndPassword() {
        // Given
        AuthCallback callback = Mockito.mock(AuthCallback.class);
        Mockito.doAnswer(new Answer() {
            @Override
{'fraction_non_alphanumeric': 0.11599203715992037, 'fraction_numerical': 0.0022561380225613803, 'mean_word_length': 3.90625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986985', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2263, 'n_words': 415}