// Path: planb-core/src/androidTest/java/at/favre/lib/planb/MockDataGenerator.java
// public class MockDataGenerator {
//     public static CrashData createCrashData(Throwable t) {
//         return CrashDataUtil.createFromCrash(new PlanBConfig.Builder().build(),
//                 Thread.currentThread(), t, Collections.<String, String>emptyMap());
//     }
// }
// 
// Path: planb-core/src/main/java/at/favre/lib/planb/exceptions/MockRuntimeException.java
// public class MockRuntimeException extends RuntimeException {
//     public MockRuntimeException() {
//         super("This is a simple mock exception that will be thrown on purpose. This is NOT a bug or error of the app.");
//     }
// }
// 
// Path: planb-core/src/main/java/at/favre/lib/planb/interfaces/CrashDataHandler.java
// public interface CrashDataHandler {
// 
//     /**
//      * Gets the latest crashdata and resets the internal
//      * unhandled crash flag
//      *
//      * @return the latest crash data or null the handler is empty
//      */
//     @Nullable
//     CrashData getLatest();
// 
//     /**
//      * @return all persisted crash data
//      */
//     @NonNull
//     List<CrashData> getAll();
// 
//     /**
//      * @return currently persisted crash data
//      */
//     int size();
// 
//     /**
//      * If {@link #persistCrashData(CrashData)} was called this will return
//      * true until {@link #getLatest()} is called. Not every crash must be handled.
//      * One call to {@link #getLatest()} will reset multiple new crash data.
//      * <p>
//      * This is for checking after the app restarts if an crash occurred.
//      *
//      * @return true if an crash that wasn't handled was found
//      */
//     boolean hasUnhandledCrash();
// 
//     /**
//      * Persists a new crashdata
//      *
//      * @param crashData to persist
//      */
//     void persistCrashData(@NonNull CrashData crashData);
// 
//     /**
//      * Returns the count of crash data entries that were persisted after
//      * the given time.
//      *
//      * @param fromTimestamp timestamp from {@link java.util.Date}
//      * @return count of entries
//      */
//     int countOfCrashesSince(long fromTimestamp);
// 
//     /**
//      * Clears all persisted crash data entries.
//      */
//     void clear();
// }


import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.EmptyStackException;
import at.favre.lib.planb.MockDataGenerator;
import at.favre.lib.planb.exceptions.MockRuntimeException;
import at.favre.lib.planb.interfaces.CrashDataHandler;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
package at.favre.lib.planb.data;






/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class SharedPreferenceCrashDataHandlerTest {
    private CrashDataHandler handler;

    @Before
    public void setup() {
        handler = new SharedPrefCrashDataHandler(InstrumentationRegistry.getTargetContext());
        handler.clear();
    }

    @Test
    public void testDefaults() {
        assertNotNull(handler);
        assertTrue(handler.getAll().isEmpty());
        assertNull(handler.getLatest());
        assertEquals(0, handler.countOfCrashesSince(0));
        assertFalse(handler.hasUnhandledCrash());
        assertEquals(0, handler.size());
    }

    @Test
    public void testAdd() {
        CrashData crashData = createCrashData(new IllegalArgumentException());
        handler.persistCrashData(crashData);
        assertEquals(1, handler.countOfCrashesSince(0));
// Path: planb-core/src/androidTest/java/at/favre/lib/planb/MockDataGenerator.java
// public class MockDataGenerator {
//     public static CrashData createCrashData(Throwable t) {
//         return CrashDataUtil.createFromCrash(new PlanBConfig.Builder().build(),
//                 Thread.currentThread(), t, Collections.<String, String>emptyMap());
//     }
// }
// 
// Path: planb-core/src/main/java/at/favre/lib/planb/exceptions/MockRuntimeException.java
// public class MockRuntimeException extends RuntimeException {
//     public MockRuntimeException() {
//         super("This is a simple mock exception that will be thrown on purpose. This is NOT a bug or error of the app.");
//     }
// }
// 
// Path: planb-core/src/main/java/at/favre/lib/planb/interfaces/CrashDataHandler.java
// public interface CrashDataHandler {
// 
//     /**
//      * Gets the latest crashdata and resets the internal
//      * unhandled crash flag
//      *
//      * @return the latest crash data or null the handler is empty
//      */
//     @Nullable
//     CrashData getLatest();
// 
//     /**
//      * @return all persisted crash data
//      */
//     @NonNull
//     List<CrashData> getAll();
// 
//     /**
//      * @return currently persisted crash data
//      */
//     int size();
// 
//     /**
//      * If {@link #persistCrashData(CrashData)} was called this will return
//      * true until {@link #getLatest()} is called. Not every crash must be handled.
//      * One call to {@link #getLatest()} will reset multiple new crash data.
//      * <p>
//      * This is for checking after the app restarts if an crash occurred.
//      *
//      * @return true if an crash that wasn't handled was found
//      */
//     boolean hasUnhandledCrash();
// 
//     /**
//      * Persists a new crashdata
//      *
//      * @param crashData to persist
//      */
//     void persistCrashData(@NonNull CrashData crashData);
// 
//     /**
//      * Returns the count of crash data entries that were persisted after
//      * the given time.
//      *
//      * @param fromTimestamp timestamp from {@link java.util.Date}
//      * @return count of entries
//      */
//     int countOfCrashesSince(long fromTimestamp);
// 
//     /**
//      * Clears all persisted crash data entries.
//      */
//     void clear();
// }


// Path: planb-core/src/androidTest/java/at/favre/lib/planb/data/SharedPreferenceCrashDataHandlerTest.java
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.EmptyStackException;
import at.favre.lib.planb.MockDataGenerator;
import at.favre.lib.planb.exceptions.MockRuntimeException;
import at.favre.lib.planb.interfaces.CrashDataHandler;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

package at.favre.lib.planb.data;






/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class SharedPreferenceCrashDataHandlerTest {
    private CrashDataHandler handler;

    @Before
    public void setup() {
        handler = new SharedPrefCrashDataHandler(InstrumentationRegistry.getTargetContext());
        handler.clear();
    }

    @Test
    public void testDefaults() {
        assertNotNull(handler);
        assertTrue(handler.getAll().isEmpty());
        assertNull(handler.getLatest());
        assertEquals(0, handler.countOfCrashesSince(0));
        assertFalse(handler.hasUnhandledCrash());
        assertEquals(0, handler.size());
    }

    @Test
    public void testAdd() {
        CrashData crashData = createCrashData(new IllegalArgumentException());
        handler.persistCrashData(crashData);
        assertEquals(1, handler.countOfCrashesSince(0));
        assertEquals(1, handler.size());