// Path: core/src/main/java/com/mindscapehq/raygun4java/core/handlers/offlinesupport/RaygunOnFailedSendOfflineStorageHandler.java
// public class RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory {
// 
//     static final String fileExtension = ".raygunpayload";
//     private final String apiKeyHash;
//     private Random random = new Random();
//     private String storageDir;
//     File storage;
//     boolean enabled = true;
//     private boolean exceptionLogged = false;
//     boolean hasStoredExceptions = true;
//     private volatile Runnable sendingStoredExceptions;
// 
//     public RaygunOnFailedSendOfflineStorageHandler(String storageDir, String apiKey) {
//         this.apiKeyHash = new BigInteger(String.valueOf(Math.abs(apiKey.hashCode()))).toString(36);
//         this.storageDir = storageDir;
//     }
// 
//     public void setEnabled(boolean enabled) {
//         this.enabled = enabled;
//     }
// 
//     public RaygunMessage onBeforeSend(RaygunClient client, RaygunMessage message) {
//         if (enabled && hasStoredExceptions && sendingStoredExceptions == null) {
//             // begin sending on new thread
//             synchronized (this) {
//                 if (sendingStoredExceptions == null) {
//                     sendingStoredExceptions = new RaygunSendStoredExceptions(client, this.getStorage(this.storageDir));
//                     new Thread(new Runnable() {
//                         public void run() {
//                             sendingStoredExceptions.run();
//                             sendingStoredExceptions = null;
//                             hasStoredExceptions = false;
//                         }
//                     }).start();
//                 }
//             }
//         }
// 
//         return message;
//     }
// 
//     public String onFailedSend(RaygunClient client, String jsonPayload) {
//         if (!enabled) {
//             return jsonPayload;
//         }
// 
//         OutputStream fileOutputStream = null;
//         try {
//             File file = getFile();
// 
//             if (file == null) {
//                 return jsonPayload;
//             }
// 
//             fileOutputStream = getOutputStream(file);
//             fileOutputStream.write(jsonPayload.getBytes());
// 
//             exceptionLogged = false;
//             hasStoredExceptions = true;
//         } catch (Exception e1) {
//             if(!exceptionLogged) {
//                 Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage());
//                 exceptionLogged = true;
//             }
//         } finally {
//             if (fileOutputStream != null) {
//                 try {
//                     fileOutputStream.close();
//                 } catch (IOException e1) {
//                     Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage());
//                 }
//             }
// 
//         }
// 
//         return jsonPayload;
//     }
// 
//     File getFile() {
//         try {
//             if (storage == null) {
//                 synchronized (this) {
//                     if (storage == null) {
//                         storage = getStorage(storageDir);
// 
//                         if (!storage.exists()) {
//                             if(!storage.mkdirs()) {
//                                 return disable();
//                             }
//                         }
//                     }
// 
//                     // this case could occur if a second thread was blocked on the synchronized
//                     if (!enabled) {
//                         return disable();
//                     }
//                 }
//             }
// 
//             File file = getFile(storage, random.nextInt()+ fileExtension);
// 
//             if (!file.createNewFile()) {
//                 return disable();
//             }
// 
//             return file;
//         } catch (Exception e) {
//             return disable();
//         }
//     }
// 
//     OutputStream getOutputStream(File file) throws FileNotFoundException {
//         return new FileOutputStream(file);
//     }
// 
//     File getStorage(String storageDir) {
//         return new File(new File(storageDir).getAbsolutePath(), ".raygun_offline_storage_" + apiKeyHash).getAbsoluteFile();
//     }
// 
//     File getFile(File storage, String name) {
//         return new File(storage, name).getAbsoluteFile();
//     }
// 
//     private File disable() {
//         enabled = false;
//         return null;
//     }
// 
//     public IRaygunOnBeforeSend create() {
//         return this;
//     }
// }
// 
// Path: core/src/main/java/com/mindscapehq/raygun4java/core/handlers/requestfilters/RaygunDuplicateErrorFilterFactory.java
// public class RaygunDuplicateErrorFilterFactory implements IRaygunSendEventFactory {
// 
//     private ThreadLocal<RaygunDuplicateErrorFilter> instance = new ThreadLocal<RaygunDuplicateErrorFilter>();
// 
//     /**
//      * When called twice in a row from the same thread, both calls will receive the same instance,
//      * a third call will return a new instance
//      * @return
//      */
//     // this will haunt me for eternity
//     public RaygunDuplicateErrorFilter create() {
//         RaygunDuplicateErrorFilter filter = instance.get();
//         if (filter == null) {
//             filter = new RaygunDuplicateErrorFilter();
//             instance.set(filter);
//             return filter;
//         } else {
//             instance.remove();
//             return filter;
//         }
//     }
// }


import com.mindscapehq.raygun4java.core.handlers.offlinesupport.RaygunOnFailedSendOfflineStorageHandler;
import com.mindscapehq.raygun4java.core.handlers.requestfilters.RaygunDuplicateErrorFilterFactory;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.mindscapehq.raygun4java.core;




public class RaygunClientFactoryTest {

    @Mock
    private IRaygunSendEventFactory<IRaygunOnBeforeSend> onBeforeSendhandlerFactory;
    @Mock
// Path: core/src/main/java/com/mindscapehq/raygun4java/core/handlers/offlinesupport/RaygunOnFailedSendOfflineStorageHandler.java
// public class RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory {
// 
//     static final String fileExtension = ".raygunpayload";
//     private final String apiKeyHash;
//     private Random random = new Random();
//     private String storageDir;
//     File storage;
//     boolean enabled = true;
//     private boolean exceptionLogged = false;
//     boolean hasStoredExceptions = true;
//     private volatile Runnable sendingStoredExceptions;
// 
//     public RaygunOnFailedSendOfflineStorageHandler(String storageDir, String apiKey) {
//         this.apiKeyHash = new BigInteger(String.valueOf(Math.abs(apiKey.hashCode()))).toString(36);
//         this.storageDir = storageDir;
//     }
// 
//     public void setEnabled(boolean enabled) {
//         this.enabled = enabled;
//     }
// 
//     public RaygunMessage onBeforeSend(RaygunClient client, RaygunMessage message) {
//         if (enabled && hasStoredExceptions && sendingStoredExceptions == null) {
//             // begin sending on new thread
//             synchronized (this) {
//                 if (sendingStoredExceptions == null) {
//                     sendingStoredExceptions = new RaygunSendStoredExceptions(client, this.getStorage(this.storageDir));
//                     new Thread(new Runnable() {
//                         public void run() {
//                             sendingStoredExceptions.run();
//                             sendingStoredExceptions = null;
//                             hasStoredExceptions = false;
//                         }
//                     }).start();
//                 }
//             }
//         }
// 
//         return message;
//     }
// 
//     public String onFailedSend(RaygunClient client, String jsonPayload) {
//         if (!enabled) {
//             return jsonPayload;
//         }
// 
//         OutputStream fileOutputStream = null;
//         try {
//             File file = getFile();
// 
//             if (file == null) {
//                 return jsonPayload;
//             }
// 
//             fileOutputStream = getOutputStream(file);
//             fileOutputStream.write(jsonPayload.getBytes());
// 
//             exceptionLogged = false;
//             hasStoredExceptions = true;
//         } catch (Exception e1) {
//             if(!exceptionLogged) {
//                 Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage());
//                 exceptionLogged = true;
//             }
//         } finally {
//             if (fileOutputStream != null) {
//                 try {
//                     fileOutputStream.close();
//                 } catch (IOException e1) {
//                     Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage());
//                 }
//             }
// 
//         }
// 
//         return jsonPayload;
//     }
// 
//     File getFile() {
//         try {
//             if (storage == null) {
//                 synchronized (this) {
//                     if (storage == null) {
//                         storage = getStorage(storageDir);
// 
//                         if (!storage.exists()) {
//                             if(!storage.mkdirs()) {
//                                 return disable();
//                             }
//                         }
//                     }
// 
//                     // this case could occur if a second thread was blocked on the synchronized
//                     if (!enabled) {
//                         return disable();
//                     }
//                 }
//             }
// 
//             File file = getFile(storage, random.nextInt()+ fileExtension);
// 
//             if (!file.createNewFile()) {
//                 return disable();
//             }
// 
//             return file;
//         } catch (Exception e) {
//             return disable();
//         }
//     }
// 
//     OutputStream getOutputStream(File file) throws FileNotFoundException {
//         return new FileOutputStream(file);
//     }
// 
//     File getStorage(String storageDir) {
//         return new File(new File(storageDir).getAbsolutePath(), ".raygun_offline_storage_" + apiKeyHash).getAbsoluteFile();
//     }
// 
//     File getFile(File storage, String name) {
//         return new File(storage, name).getAbsoluteFile();
//     }
// 
//     private File disable() {
//         enabled = false;
//         return null;
//     }
// 
//     public IRaygunOnBeforeSend create() {
//         return this;
//     }
// }
// 
// Path: core/src/main/java/com/mindscapehq/raygun4java/core/handlers/requestfilters/RaygunDuplicateErrorFilterFactory.java
// public class RaygunDuplicateErrorFilterFactory implements IRaygunSendEventFactory {
// 
//     private ThreadLocal<RaygunDuplicateErrorFilter> instance = new ThreadLocal<RaygunDuplicateErrorFilter>();
// 
//     /**
//      * When called twice in a row from the same thread, both calls will receive the same instance,
//      * a third call will return a new instance
//      * @return
//      */
//     // this will haunt me for eternity
//     public RaygunDuplicateErrorFilter create() {
//         RaygunDuplicateErrorFilter filter = instance.get();
//         if (filter == null) {
//             filter = new RaygunDuplicateErrorFilter();
//             instance.set(filter);
//             return filter;
//         } else {
//             instance.remove();
//             return filter;
//         }
//     }
// }


// Path: core/src/test/java/com/mindscapehq/raygun4java/core/RaygunClientFactoryTest.java
import com.mindscapehq.raygun4java.core.handlers.offlinesupport.RaygunOnFailedSendOfflineStorageHandler;
import com.mindscapehq.raygun4java.core.handlers.requestfilters.RaygunDuplicateErrorFilterFactory;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

package com.mindscapehq.raygun4java.core;




public class RaygunClientFactoryTest {

    @Mock
    private IRaygunSendEventFactory<IRaygunOnBeforeSend> onBeforeSendhandlerFactory;
    @Mock
    private IRaygunSendEventFactory<IRaygunOnAfterSend> onAfterSendhandlerFactory;