hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1598488 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/impl/nio/NHttpConnectionBase.java test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java
Date Fri, 30 May 2014 08:15:54 GMT
Author: olegk
Date: Fri May 30 08:15:53 2014
New Revision: 1598488

URL: http://svn.apache.org/r1598488
Log:
Shorter NHttpConnectionBase#toString

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1598488&r1=1598487&r2=1598488&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
Fri May 30 08:15:53 2014
@@ -589,28 +589,17 @@ public class NHttpConnectionBase
 
     @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder();
         final SocketAddress remoteAddress = this.session.getRemoteAddress();
         final SocketAddress localAddress = this.session.getLocalAddress();
         if (remoteAddress != null && localAddress != null) {
+            final StringBuilder buffer = new StringBuilder();
             NetUtils.formatAddress(buffer, localAddress);
             buffer.append("<->");
             NetUtils.formatAddress(buffer, remoteAddress);
+            return buffer.toString();
+        } else {
+            return "[Not bound]";
         }
-        buffer.append("[");
-        switch (this.status) {
-        case ACTIVE:
-            buffer.append("ACTIVE");
-            break;
-        case CLOSING:
-            buffer.append("CLOSING");
-            break;
-        case CLOSED:
-            buffer.append("CLOSED");
-            break;
-        }
-        buffer.append("]");
-        return buffer.toString();
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java?rev=1598488&r1=1598487&r2=1598488&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestNHttpConnectionBase.java
Fri May 30 08:15:53 2014
@@ -31,8 +31,6 @@ import java.net.InetSocketAddress;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 
-import junit.framework.Assert;
-
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpVersion;
 import org.apache.http.impl.entity.LaxContentLengthStrategy;
@@ -48,6 +46,7 @@ import org.apache.http.nio.NHttpConnecti
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.protocol.HTTP;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -74,7 +73,7 @@ public class TestNHttpConnectionBase {
 
     @Test
     public void testBasics() throws Exception {
-        Assert.assertEquals("[ACTIVE]", conn.toString());
+        Assert.assertEquals("[Not bound]", conn.toString());
 
         Mockito.verify(session).setBufferStatus(conn);
     }
@@ -93,7 +92,7 @@ public class TestNHttpConnectionBase {
 
         Mockito.verify(session, Mockito.times(2)).setBufferStatus(conn);
 
-        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80[ACTIVE]", conn.toString());
+        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80", conn.toString());
         Assert.assertTrue(conn.isOpen());
         Assert.assertEquals(8888, conn.getLocalPort());
         Assert.assertEquals(80, conn.getRemotePort());
@@ -114,7 +113,7 @@ public class TestNHttpConnectionBase {
         conn.close();
 
         Assert.assertEquals(NHttpConnection.CLOSED, conn.getStatus());
-        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80[CLOSED]", conn.toString());
+        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80", conn.toString());
 
         Mockito.verify(session).close();
     }
@@ -135,7 +134,7 @@ public class TestNHttpConnectionBase {
         Assert.assertEquals(NHttpConnection.CLOSING, conn.getStatus());
         conn.close();
         Assert.assertEquals(NHttpConnection.CLOSING, conn.getStatus());
-        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80[CLOSING]", conn.toString());
+        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80", conn.toString());
 
         Mockito.verify(session).setEvent(SelectionKey.OP_WRITE);
         Mockito.verify(session, Mockito.never()).close();
@@ -155,7 +154,7 @@ public class TestNHttpConnectionBase {
         conn.shutdown();
 
         Assert.assertEquals(NHttpConnection.CLOSED, conn.getStatus());
-        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80[CLOSED]", conn.toString());
+        Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80", conn.toString());
 
         Mockito.verify(session).shutdown();
     }



Mime
View raw message