package com.notnoop.apns.internal;

import java.io.ByteArrayOutputStream;

import javax.net.SocketFactory;

import org.junit.Assert;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import com.notnoop.apns.ApnsNotification;

@RunWith(Theories.class)
public class ApnsConnectionTest {
    ApnsNotification msg = new ApnsNotification ("a87d8878d878a79", "{\"aps\":{}}");

    static ByteArrayOutputStream baos = new ByteArrayOutputStream();

    @DataPoint public static SocketFactory SIMPLE = MockingUtils.mockSocketFactory(baos);
    @DataPoint public static SocketFactory CLOSED_RETRY = MockingUtils.mockClosedThenOpenSocket(baos, true, 1);
    @DataPoint public static SocketFactory ERROR_RETRY = MockingUtils.mockClosedThenOpenSocket(baos, false, 1);
    @DataPoint public static SocketFactory TWICE_ERROR_RETRY = MockingUtils.mockClosedThenOpenSocket(baos, false, 2);

    @Theory
    public void packetSentRegardlesss(SocketFactory sf) {
        baos.reset();
        ApnsConnection connection = new ApnsConnection(sf, "localhost", 80);
        connection.DELAY_IN_MS = 0;
        connection.sendMessage(msg);
        Assert.assertArrayEquals(msg.marshall(), baos.toByteArray());
    }
}

@@ -29,16 +29,73 @@
 ernal;%0A%0A
+import static com.notnoop.apns.internal.MockingUtils.*;%0A%0A
 import j
@@ -204,168 +204,12 @@
 nit.
-experimental.theories.DataPoint;%0Aimport org.junit.experimental.theories.Theories;%0Aimport org.junit.experimental.theories.Theory;%0Aimport org.junit.runner.RunWith
+Test
 ;%0A%0Ai
@@ -254,33 +254,8 @@
 n;%0A%0A
-@RunWith(Theories.class)%0A
 publ
@@ -374,22 +374,62 @@
 );%0A%0A    
-static
+@Test%0A    public void simpleSocket() %7B%0A       
  ByteArr
@@ -483,37 +483,233 @@
 ();%0A
-%0A    @DataPoint public static
+        SocketFactory factory = mockSocketFactory(baos);%0A        packetSentRegardless(factory, baos);%0A    %7D%0A%0A    @Test%0A    public void closedSocket() %7B%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A       
  Soc
@@ -723,48 +723,97 @@
 ory 
-SIMPLE = MockingUtils.mockSocketF
+factory = mockClosedThenOpenSocket(baos, true, 1);%0A        packetSentRegardless(f
 actory
-(
+, 
 baos
@@ -823,75 +823,149 @@
     
-@DataPoint public static SocketFactory CLOSED_RETRY = MockingUtils.
+%7D%0A%0A    @Test%0A    public void errorOnce() %7B%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A        SocketFactory factory = 
 mock
@@ -983,35 +983,36 @@
 penSocket(baos, 
-tru
+fals
 e, 1);%0A    @Data
@@ -1010,74 +1010,195 @@
     
-@DataPoint public static SocketFactory ERROR_RETRY = MockingUtils.
+    packetSentRegardless(factory, baos);%0A    %7D%0A%0A    @Test%0A    public void errorTwice() %7B%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A        SocketFactory factory = 
 mock
@@ -1235,88 +1235,292 @@
 se, 
-1
+2
 );%0A    
-@DataPoint public static SocketFactory TWICE_ERROR_RETRY = MockingUtils.
+    packetSentRegardless(factory, baos);%0A    %7D%0A%0A    /**%0A     * Connection fails after three retries%0A     */%0A    @Test(expected = Exception.class)%0A    public void errorThrice() %7B%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A        SocketFactory factory = 
 mock
@@ -1557,35 +1557,75 @@
 se, 
-2
+3
 );%0A
-%0A
     
-@Theory%0A    public
+    packetSentRegardless(factory, baos);%0A    %7D%0A%0A    private
  voi
@@ -1646,17 +1646,16 @@
 gardless
-s
 (SocketF
@@ -1667,33 +1667,39 @@
 y sf
-) %7B%0A        baos.reset();
+, ByteArrayOutputStream baos) %7B
 %0A   

bring back simple tests