java: reorganize ProtocolTestBase slightly

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@930530 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/test/org/apache/thrift/protocol/ProtocolTestBase.java b/lib/java/test/org/apache/thrift/protocol/ProtocolTestBase.java
index 3e4d0a6..f8e316a 100644
--- a/lib/java/test/org/apache/thrift/protocol/ProtocolTestBase.java
+++ b/lib/java/test/org/apache/thrift/protocol/ProtocolTestBase.java
@@ -38,33 +38,59 @@
 
 public abstract class ProtocolTestBase extends TestCase {
 
+  /** Does it make sense to call methods like writeI32 directly on your protocol? */
   protected abstract boolean canBeUsedNaked();
-  
+
+  /** The protocol factory for the protocol being tested. */
   protected abstract TProtocolFactory getFactory();
 
-  public void testProtocol() throws Exception {
+  public void testDouble() throws Exception {
     if (canBeUsedNaked()) {
-      internalTestNakedByte();
-    }
-    for (int i = 0; i < 128; i++) {
-      internalTestByteField((byte)i);
-      internalTestByteField((byte)-i);
+      TMemoryBuffer buf = new TMemoryBuffer(1000);
+      TProtocol proto = getFactory().getProtocol(buf);
+      proto.writeDouble(123.456);
+      assertEquals(123.456, proto.readDouble());
     }
 
-    for (int s : Arrays.asList(0, 1, 7, 150, 15000, 0x7fff, -1, -7, -150, -15000, -0x7fff)) {
-      if (canBeUsedNaked()) {
-        internalTestNakedI16((short)s);
+    internalTestStructField(new StructFieldTestCase(TType.DOUBLE, (short)15) {
+      @Override
+      public void readMethod(TProtocol proto) throws TException {
+        assertEquals(123.456, proto.readDouble());
       }
-      internalTestI16Field((short)s);
-    }
 
-    for (int i : Arrays.asList(0, 1, 7, 150, 15000, 31337, 0xffff, 0xffffff, -1, -7, -150, -15000, -0xffff, -0xffffff)) {
-      if (canBeUsedNaked()) {
-        internalTestNakedI32(i);
+      @Override
+      public void writeMethod(TProtocol proto) throws TException {
+        proto.writeDouble(123.456);
       }
-      internalTestI32Field(i);
-    }
+    });
+  }
 
+  public void testSerialization() throws Exception {
+    internalTestSerialization(OneOfEach.class, Fixtures.oneOfEach);
+    internalTestSerialization(Nesting.class, Fixtures.nesting);
+    internalTestSerialization(HolyMoley.class, Fixtures.holyMoley);
+    internalTestSerialization(CompactProtoTestStruct.class, Fixtures.compactProtoTestStruct);
+  }
+
+  public void testBinary() throws Exception {
+    for (byte[] b : Arrays.asList(new byte[0], new byte[]{0,1,2,3,4,5,6,7,8,9,10}, new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, new byte[128])) {
+      if (canBeUsedNaked()) {
+        internalTestNakedBinary(b);
+      }
+      internalTestBinaryField(b);
+    }
+  }
+
+  public void testString() throws Exception {
+    for (String s : Arrays.asList("", "short", "borderlinetiny", "a bit longer than the smallest possible")) {
+      if (canBeUsedNaked()) {
+        internalTestNakedString(s);
+      }
+      internalTestStringField(s);
+    }
+  }
+
+  public void testLong() throws Exception {
     if (canBeUsedNaked()) {
       internalTestNakedI64(0);
     }
@@ -77,33 +103,34 @@
       internalTestI64Field(1L << i);
       internalTestI64Field(-(1L << i));
     }
+  }
 
-    internalTestDouble();
-
-    for (String s : Arrays.asList("", "short", "borderlinetiny", "a bit longer than the smallest possible")) {
+  public void testInt() throws Exception {
+    for (int i : Arrays.asList(0, 1, 7, 150, 15000, 31337, 0xffff, 0xffffff, -1, -7, -150, -15000, -0xffff, -0xffffff)) {
       if (canBeUsedNaked()) {
-        internalTestNakedString(s);
+        internalTestNakedI32(i);
       }
-      internalTestStringField(s);
+      internalTestI32Field(i);
     }
+  }
 
-    for (byte[] b : Arrays.asList(new byte[0], new byte[]{0,1,2,3,4,5,6,7,8,9,10}, new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, new byte[128])) {
+  public void testShort() throws Exception {
+    for (int s : Arrays.asList(0, 1, 7, 150, 15000, 0x7fff, -1, -7, -150, -15000, -0x7fff)) {
       if (canBeUsedNaked()) {
-        internalTestNakedBinary(b);
+        internalTestNakedI16((short)s);
       }
-      internalTestBinaryField(b);
+      internalTestI16Field((short)s);
     }
+  }
 
-    internalTestSerialization(OneOfEach.class, Fixtures.oneOfEach);
-    internalTestSerialization(Nesting.class, Fixtures.nesting);
-    internalTestSerialization(HolyMoley.class, Fixtures.holyMoley);
-    internalTestSerialization(CompactProtoTestStruct.class, Fixtures.compactProtoTestStruct);
-
-    internalTestMessage();
-
-    internalTestServerRequest();
-
-    internalTestTDeserializer();
+  public void testByte() throws Exception {
+    if (canBeUsedNaked()) {
+      internalTestNakedByte();
+    }
+    for (int i = 0; i < 128; i++) {
+      internalTestByteField((byte)i);
+      internalTestByteField((byte)-i);
+    }
   }
 
   private void internalTestNakedByte() throws Exception {
@@ -182,27 +209,6 @@
     });
   }
 
-  private void internalTestDouble() throws Exception {
-    if (canBeUsedNaked()) {
-      TMemoryBuffer buf = new TMemoryBuffer(1000);
-      TProtocol proto = getFactory().getProtocol(buf);
-      proto.writeDouble(123.456);
-      assertEquals(123.456, proto.readDouble());
-    }
-    
-    internalTestStructField(new StructFieldTestCase(TType.DOUBLE, (short)15) {
-      @Override
-      public void readMethod(TProtocol proto) throws TException {
-        assertEquals(123.456, proto.readDouble());
-      }
-
-      @Override
-      public void writeMethod(TProtocol proto) throws TException {
-        proto.writeDouble(123.456);
-      }
-    });
-  }
-
   private void internalTestNakedString(String str) throws Exception {
     TMemoryBuffer buf = new TMemoryBuffer(0);
     TProtocol proto = getFactory().getProtocol(buf);
@@ -258,7 +264,7 @@
     assertEquals(expected, actual);
   }
 
-  private void internalTestMessage() throws Exception {
+  public void testMessage() throws Exception {
     List<TMessage> msgs = Arrays.asList(new TMessage[]{
       new TMessage("short message name", TMessageType.CALL, 0),
       new TMessage("1", TMessageType.REPLY, 12345),
@@ -280,7 +286,7 @@
     }
   }
 
-  private void internalTestServerRequest() throws Exception {
+  public void testServerRequest() throws Exception {
     Srv.Iface handler = new Srv.Iface() {
       public int Janky(int i32arg) throws TException {
         return i32arg * 2;
@@ -317,7 +323,7 @@
     assertEquals(2, testClient.recv_Janky());
   }
 
-  private void internalTestTDeserializer() throws TException {
+  public void testTDeserializer() throws TException {
     TSerializer ser = new TSerializer(getFactory());
     byte[] bytes = ser.serialize(Fixtures.compactProtoTestStruct);