commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1748964 - /commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
Date Sat, 18 Jun 2016 11:08:04 GMT
Author: britter
Date: Sat Jun 18 11:08:04 2016
New Revision: 1748964

URL: http://svn.apache.org/viewvc?rev=1748964&view=rev
Log:
Let JUnit propagate errors instead of translating them into a failure

Modified:
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java

Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java?rev=1748964&r1=1748963&r2=1748964&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/ElementValueGenTestCase.java Sat
Jun 18 11:08:04 2016
@@ -43,7 +43,7 @@ public class ElementValueGenTestCase ext
     /**
      * Create primitive element values
      */
-    public void testCreateIntegerElementValue()
+    public void testCreateIntegerElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -57,7 +57,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateFloatElementValue()
+    public void testCreateFloatElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -71,7 +71,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateDoubleElementValue()
+    public void testCreateDoubleElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -85,7 +85,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateLongElementValue()
+    public void testCreateLongElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -99,7 +99,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateCharElementValue()
+    public void testCreateCharElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -113,7 +113,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateByteElementValue()
+    public void testCreateByteElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -127,7 +127,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateBooleanElementValue()
+    public void testCreateBooleanElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -141,7 +141,7 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    public void testCreateShortElementValue()
+    public void testCreateShortElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -157,7 +157,7 @@ public class ElementValueGenTestCase ext
 
     // //
     // Create string element values
-    public void testCreateStringElementValue()
+    public void testCreateStringElementValue() throws Exception
     {
         // Create HelloWorld
         ClassGen cg = createClassGen("HelloWorld");
@@ -174,7 +174,7 @@ public class ElementValueGenTestCase ext
 
     // //
     // Create enum element value
-    public void testCreateEnumElementValue()
+    public void testCreateEnumElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -198,7 +198,7 @@ public class ElementValueGenTestCase ext
 
     // //
     // Create class element value
-    public void testCreateClassElementValue()
+    public void testCreateClassElementValue() throws Exception
     {
         ClassGen cg = createClassGen("HelloWorld");
         ConstantPoolGen cp = cg.getConstantPool();
@@ -209,24 +209,20 @@ public class ElementValueGenTestCase ext
         checkSerialize(evg, cp);
     }
 
-    private void checkSerialize(final ElementValueGen evgBefore, final ConstantPoolGen cpg)
{
-        try {
-            String beforeValue = evgBefore.stringifyValue();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            try (DataOutputStream dos = new DataOutputStream(baos)) {
-                evgBefore.dump(dos);
-                dos.flush();
-            }
-            ElementValueGen evgAfter;
-            try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())))
{
-                evgAfter = ElementValueGen.readElementValue(dis, cpg);
-            }
-            String afterValue = evgAfter.stringifyValue();
-            if (!beforeValue.equals(afterValue)) {
-                fail("Deserialization failed: before='" + beforeValue + "' after='" + afterValue
+ "'");
-            }
-        } catch (IOException ioe) {
-            fail("Unexpected exception whilst checking serialization: " + ioe);
+    private void checkSerialize(final ElementValueGen evgBefore, final ConstantPoolGen cpg)
throws IOException {
+        String beforeValue = evgBefore.stringifyValue();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try (DataOutputStream dos = new DataOutputStream(baos)) {
+            evgBefore.dump(dos);
+            dos.flush();
+        }
+        ElementValueGen evgAfter;
+        try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())))
{
+            evgAfter = ElementValueGen.readElementValue(dis, cpg);
+        }
+        String afterValue = evgAfter.stringifyValue();
+        if (!beforeValue.equals(afterValue)) {
+            fail("Deserialization failed: before='" + beforeValue + "' after='" + afterValue
+ "'");
         }
     }
 }



Mime
View raw message