package com.braintreepayments.api;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;

import org.junit.Before;
import org.junit.Test;

import java.util.UUID;

public class UUIDHelperUnitTest {

    private BraintreeSharedPreferences braintreeSharedPreferences;
    private Context context;

    @Before
    public void beforeEach() {
        braintreeSharedPreferences = mock(BraintreeSharedPreferences.class);
        context = mock(Context.class);
    }

    @Test
    public void getInstallationGUID_returnsNewGUIDWhenOneDoesNotExistAndPersistsIt() throws UnexpectedException {
        when(braintreeSharedPreferences.getString(context, "InstallationGUID", null)).thenReturn(null);

        UUIDHelper sut = new UUIDHelper();

        String uuid = sut.getInstallationGUID(context, braintreeSharedPreferences);
        assertNotNull(uuid);
        verify(braintreeSharedPreferences).putString(context, "InstallationGUID", uuid);
    }

    @Test
    public void getInstallationGUID_returnsExistingGUIDWhenOneExist() throws UnexpectedException {
        String uuid = UUID.randomUUID().toString();
        when(braintreeSharedPreferences.getString(context, "InstallationGUID", null)).thenReturn(uuid);

        UUIDHelper sut = new UUIDHelper();

        assertEquals(uuid, sut.getInstallationGUID(context, braintreeSharedPreferences));
    }
}

@@ -134,16 +134,161 @@
 Equals;%0A
+import static org.mockito.ArgumentMatchers.any;%0Aimport static org.mockito.ArgumentMatchers.anyString;%0Aimport static org.mockito.Mockito.doThrow;%0A
 import s
@@ -1280,32 +1280,726 @@
 , uuid);%0A    %7D%0A%0A
+    @Test%0A    public void getInstallationGUID_whenSharedPrefsFails_returnsNewGUID() throws UnexpectedException %7B%0A        UnexpectedException unexpectedException = new UnexpectedException(%22unexpected exception%22);%0A        when(%0A                braintreeSharedPreferences.getString(any(Context.class), anyString(), anyString())%0A        ).thenThrow(unexpectedException);%0A%0A        doThrow(unexpectedException)%0A                .when(braintreeSharedPreferences)%0A                .putString(any(Context.class), anyString(), anyString());%0A%0A        UUIDHelper sut = new UUIDHelper();%0A%0A        String uuid = sut.getInstallationGUID(context, braintreeSharedPreferences);%0A        assertNotNull(uuid);%0A    %7D%0A%0A
     @Test%0A    pu

Add test for UUIDHelper and shared prefs failure.