package com.notnoop.apns.internal;

import java.io.ByteArrayInputStream;

import javax.net.SocketFactory;

import org.junit.Ignore;
import org.junit.Test;

import static com.notnoop.apns.internal.ApnsFeedbackParsingUtils.*;

public class ApnsFeedbackConnectionTest {

    /** Simple Parsing **/
    @Test
    public void rowParseOneDevice() {
        checkRawSimple(Utilities.parseFeedbackStreamRaw(new ByteArrayInputStream(simple)));
    }

    @Test
    public void threeParseTwoDevices() {
        checkRawThree(Utilities.parseFeedbackStreamRaw(new ByteArrayInputStream(three)));
    }

    @Test
    public void parsedSimple() {
        checkParsedSimple(Utilities.parseFeedbackStream(new ByteArrayInputStream(simple)));
    }

    @Test
    @Ignore
    public void parsedThree() {
        checkParsedThree(Utilities.parseFeedbackStream(new ByteArrayInputStream(three)));
    }

    /** With Connection **/
    @Test
    public void connectionParsedOne() {
        SocketFactory sf = MockingUtils.mockSocketFactory(null, new ByteArrayInputStream(simple));
        ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
        checkParsedSimple(connection.getInactiveDevices());
    }

    @Test
    public void connectionParsedThree() {
        SocketFactory sf = MockingUtils.mockSocketFactory(null, new ByteArrayInputStream(three));
        ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
        checkParsedThree(connection.getInactiveDevices());
    }

}

@@ -65,16 +65,44 @@
 tStream;
+%0Aimport java.io.InputStream;
 %0A%0Aimport
@@ -249,50 +249,258 @@
 .*;%0A
-%0Apublic class ApnsFeedbackConnectionTest %7B
+import static com.notnoop.apns.internal.MockingUtils.mockClosedThenOpenSocket;%0A%0Apublic class ApnsFeedbackConnectionTest %7B%0A%0A    InputStream simpleStream = new ByteArrayInputStream(simple);%0A    InputStream threeStream = new ByteArrayInputStream(three);
 %0A%0A  
@@ -632,40 +632,20 @@
 Raw(
-new ByteArrayInputStream(simple)
+simpleStream
 ));%0A
@@ -761,39 +761,19 @@
 Raw(
-new ByteArrayInputStream(three)
+threeStream
 ));%0A
@@ -882,40 +882,20 @@
 eam(
-new ByteArrayInputStream(simple)
+simpleStream
 ));%0A
@@ -915,20 +915,8 @@
 est%0A
-    @Ignore%0A
     
@@ -1002,39 +1002,19 @@
 eam(
-new ByteArrayInputStream(three)
+threeStream
 ));%0A
@@ -1166,40 +1166,20 @@
 ll, 
-new ByteArrayInputStream(simple)
+simpleStream
 );%0A 
@@ -1457,39 +1457,1060 @@
 ll, 
-new ByteArrayInputStream(three)
+threeStream);%0A        ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, %22localhost%22, 80);%0A        checkParsedThree(connection.getInactiveDevices());%0A    %7D%0A%0A    /** Check error recover **/%0A    @Test%0A    public void feedbackWithclosedSocket() %7B%0A        SocketFactory sf = mockClosedThenOpenSocket(null, simpleStream, true, 1);%0A        ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, %22localhost%22, 80);%0A        checkParsedSimple(connection.getInactiveDevices());%0A    %7D%0A%0A    @Test%0A    public void feedbackWitherrorOnce() %7B%0A        SocketFactory sf = mockClosedThenOpenSocket(null, simpleStream, true, 2);%0A        ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, %22localhost%22, 80);%0A        connection.DELAY_IN_MS = 0;%0A        checkParsedSimple(connection.getInactiveDevices());%0A    %7D%0A%0A    /**%0A     * Connection fails after three retries%0A     */%0A    @Test(expected = Exception.class)%0A    public void feedbackWitherrorTwice() %7B%0A        SocketFactory sf = mockClosedThenOpenSocket(null, simpleStream, true, 3
 );%0A 
@@ -2593,32 +2593,68 @@
 ocalhost%22, 80);%0A
+        connection.DELAY_IN_MS = 0;%0A
         checkPar
@@ -2648,36 +2648,37 @@
      checkParsed
-Thre
+Simpl
 e(connection.get

test feedback recovery