// Path: androidsdk/src/main/java/com/wootric/androidsdk/Constants.java
// public class Constants {
// 
//     public static final long DAY_IN_MILLIS = 1000L *60L *60L *24L;
// 
//     public static final int NOT_SET = -1;
// 
//     public static final long DEFAULT_RESURVEY_DAYS = 90L;
// 
//     public static final long DEFAULT_DECLINE_RESURVEY_DAYS = 30L;
// 
//     public static final String TAG = "WOOTRIC_SDK";
// 
//     public static final String CES = "CES";
// 
//     public static final String CSAT = "CSAT";
// }


import android.content.Context;
import android.content.SharedPreferences;
import com.wootric.androidsdk.Constants;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.ref.WeakReference;
import java.util.Date;
    @Before
    public void before() throws Exception {
        this.context = Mockito.mock(Context.class);
        this.weakReference = Mockito.mock(WeakReference.class);
        this.prefs = Mockito.mock(SharedPreferences.class);
        preferencesUtils = new PreferencesUtils(weakReference);
        Mockito.when(weakReference.get()).thenReturn(context);
        Mockito.when(context.getSharedPreferences(Mockito.anyString(), Mockito.anyInt())).thenReturn(prefs);
    }

    @Test
    public void touchLastSurveyed_whenResponse() throws Exception {
        SharedPreferences.Editor mockedEditor = Mockito.mock(SharedPreferences.Editor.class);
        Mockito.when(prefs.edit()).thenReturn(mockedEditor);
        preferencesUtils.touchLastSurveyed(true, 90);
        Mockito.verify(mockedEditor).apply();
    }

    @Test
    public void wasRecentlySurveyed_whenResponseAndSurveyedDefault() throws Exception {
        long now = new Date().getTime();

        Mockito.when(prefs.contains(Mockito.anyString())).thenReturn(true);
        Mockito.when(prefs.getString(Mockito.eq("type"), Mockito.anyString())).thenReturn("response");
        Mockito.when(prefs.getInt(Mockito.eq("resurvey_days"), Mockito.anyInt())).thenReturn(-1);

        Mockito.when(prefs.getLong(Mockito.eq("surveyed"), Mockito.anyLong())).thenReturn(now);
        Assert.assertEquals(true, preferencesUtils.wasRecentlySurveyed());


// Path: androidsdk/src/main/java/com/wootric/androidsdk/Constants.java
// public class Constants {
// 
//     public static final long DAY_IN_MILLIS = 1000L *60L *60L *24L;
// 
//     public static final int NOT_SET = -1;
// 
//     public static final long DEFAULT_RESURVEY_DAYS = 90L;
// 
//     public static final long DEFAULT_DECLINE_RESURVEY_DAYS = 30L;
// 
//     public static final String TAG = "WOOTRIC_SDK";
// 
//     public static final String CES = "CES";
// 
//     public static final String CSAT = "CSAT";
// }


// Path: androidsdk/src/test/java/com/wootric/androidsdk/utils/PreferencesUtilsTest.java
import android.content.Context;
import android.content.SharedPreferences;
import com.wootric.androidsdk.Constants;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import java.lang.ref.WeakReference;
import java.util.Date;

    @Before
    public void before() throws Exception {
        this.context = Mockito.mock(Context.class);
        this.weakReference = Mockito.mock(WeakReference.class);
        this.prefs = Mockito.mock(SharedPreferences.class);
        preferencesUtils = new PreferencesUtils(weakReference);
        Mockito.when(weakReference.get()).thenReturn(context);
        Mockito.when(context.getSharedPreferences(Mockito.anyString(), Mockito.anyInt())).thenReturn(prefs);
    }

    @Test
    public void touchLastSurveyed_whenResponse() throws Exception {
        SharedPreferences.Editor mockedEditor = Mockito.mock(SharedPreferences.Editor.class);
        Mockito.when(prefs.edit()).thenReturn(mockedEditor);
        preferencesUtils.touchLastSurveyed(true, 90);
        Mockito.verify(mockedEditor).apply();
    }

    @Test
    public void wasRecentlySurveyed_whenResponseAndSurveyedDefault() throws Exception {
        long now = new Date().getTime();

        Mockito.when(prefs.contains(Mockito.anyString())).thenReturn(true);
        Mockito.when(prefs.getString(Mockito.eq("type"), Mockito.anyString())).thenReturn("response");
        Mockito.when(prefs.getInt(Mockito.eq("resurvey_days"), Mockito.anyInt())).thenReturn(-1);

        Mockito.when(prefs.getLong(Mockito.eq("surveyed"), Mockito.anyLong())).thenReturn(now);
        Assert.assertEquals(true, preferencesUtils.wasRecentlySurveyed());


        Mockito.when(prefs.getLong(Mockito.eq("surveyed"), Mockito.anyLong())).thenReturn(now - Constants.DAY_IN_MILLIS * 32L);