package net.kencochrane.raven.event.helper;

import mockit.Expectations;
import mockit.Injectable;
import mockit.Mocked;
import mockit.Verifications;
import net.kencochrane.raven.event.EventBuilder;
import net.kencochrane.raven.event.interfaces.HttpInterface;
import net.kencochrane.raven.event.interfaces.SentryInterface;
import net.kencochrane.raven.servlet.RavenServletRequestListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import javax.servlet.http.HttpServletRequest;

public class HttpEventBuilderHelperTest {
    private HttpEventBuilderHelper httpEventBuilderHelper;
    @Injectable
    private EventBuilder mockEventBuilder;
    @Mocked("getServletRequest")
    private RavenServletRequestListener ravenServletRequestListener;
    @Injectable
    private HttpServletRequest mockHttpServletRequest;
    @Mocked
    private HttpInterface mockHttpInterface;

    @BeforeMethod
    public void setUp() throws Exception {
        httpEventBuilderHelper = new HttpEventBuilderHelper();
    }

    @Test
    public void testNoRequest() throws Exception {
        new Expectations() {{
            RavenServletRequestListener.getServletRequest();
            result = null;
        }};
        httpEventBuilderHelper.helpBuildingEvent(mockEventBuilder);

        new Verifications() {{
            mockEventBuilder.addSentryInterface((SentryInterface) any);
            times = 0;
        }};
    }

    @Test
    public void testWithRequest() throws Exception {
        new Expectations() {{
            RavenServletRequestListener.getServletRequest();
            result = mockHttpServletRequest;
        }};

        httpEventBuilderHelper.helpBuildingEvent(mockEventBuilder);

        new Verifications() {{
            mockEventBuilder.addSentryInterface(this.<HttpInterface>withNotNull());
        }};
    }
}

@@ -42,36 +42,8 @@
 r;%0A%0A
-import mockit.Expectations;%0A
 impo
@@ -86,16 +86,53 @@
 Mocked;%0A
+import mockit.NonStrictExpectations;%0A
 import m
@@ -683,181 +683,8 @@
 er;%0A
-    @Mocked(%22getServletRequest%22)%0A    private RavenServletRequestListener ravenServletRequestListener;%0A    @Injectable%0A    private HttpServletRequest mockHttpServletRequest;%0A
     
@@ -933,32 +933,41 @@
 n %7B%0A        new 
+NonStrict
 Expectations() %7B
@@ -955,32 +955,65 @@
 ictExpectations(
+RavenServletRequestListener.class
 ) %7B%7B%0A           
@@ -1193,32 +1193,128 @@
 ifications() %7B%7B%0A
+            new HttpInterface(withInstanceOf(HttpServletRequest.class));%0A            times = 0;%0A
             mock
@@ -1345,16 +1345,30 @@
 terface(
+withInstanceOf
 (SentryI
@@ -1379,13 +1379,15 @@
 face
-) any
+.class)
 );%0A 
@@ -1461,32 +1461,91 @@
 testWithRequest(
+@Injectable final HttpServletRequest mockHttpServletRequest
 ) throws Excepti
@@ -1561,16 +1561,25 @@
     new 
+NonStrict
 Expectat
@@ -1579,24 +1579,57 @@
 xpectations(
+RavenServletRequestListener.class
 ) %7B%7B%0A       
@@ -1832,32 +1832,87 @@
 ifications() %7B%7B%0A
+            new HttpInterface(mockHttpServletRequest);%0A
             mock

Improve tests for HttpEventBuilderHelper