From 926e0788a36e2c8ec7836439841baa872db11fa6 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Tue, 4 Oct 2016 14:10:29 +0000 Subject: [PATCH] ICU-12782 Merged TestwriteObject and TestReadObject to avoid test ordering issue. Changed the test case to use ByteArrayOutputStream so that the test case does not leave temporary test output file. X-SVN-Rev: 39426 --- .../test/format/CompactDecimalFormatTest.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java index ac2ce2848b8..e0a524f6759 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java @@ -8,8 +8,8 @@ */ package com.ibm.icu.dev.test.format; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.NotSerializableException; import java.io.ObjectInputStream; @@ -493,38 +493,41 @@ public class CompactDecimalFormatTest extends TestFmwk { } @Test - public void TestwriteObject() throws IOException { - FileOutputStream ba_stream = new FileOutputStream("tmp.ser"); - ObjectOutputStream objoutstream = new ObjectOutputStream(ba_stream); + public void TestWriteAndReadObject() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream objoutstream = new ObjectOutputStream(baos); CompactDecimalFormat cdf = CompactDecimalFormat.getInstance( ULocale.ENGLISH, CompactStyle.LONG); - try{ + try { objoutstream.writeObject(cdf); - } catch (NotSerializableException e) { - // Exception expected, thus return. - objoutstream.close(); - return; + } catch (NotSerializableException e) { + if (logKnownIssue("10494", "PluralRules is not serializable")) { + logln("NotSerializableException thrown when serializing CopactDecimalFormat"); + } else { + errln("NotSerializableException thrown when serializing CopactDecimalFormat"); } + } finally { objoutstream.close(); - fail("writeObject currently unsupported, expected invokation to fail but passed"); - } + } - @Test - public void TestReadObject() throws IOException, ClassNotFoundException { - FileInputStream fi_stream = new FileInputStream("tmp.ser"); - ObjectInputStream objinstream = new ObjectInputStream(fi_stream); + // This test case relies on serialized byte stream which might be premature + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream objinstream = new ObjectInputStream(bais); try { - @SuppressWarnings("unused") - CompactDecimalFormat cmpctDF = (CompactDecimalFormat) objinstream.readObject(); + cdf = (CompactDecimalFormat) objinstream.readObject(); } catch (NotSerializableException e) { - // Exception expected, thus return. - objinstream.close(); - return; + if (logKnownIssue("10494", "PluralRules is not de-serializable")) { + logln("NotSerializableException thrown when deserializing CopactDecimalFormat"); + } else { + errln("NotSerializableException thrown when deserializing CopactDecimalFormat"); + } + } catch (ClassNotFoundException e) { + errln("ClassNotFoundException: " + e.getMessage()); + } finally { + objinstream.close(); } - objinstream.close(); - fail("readObject currently unsupported, expected invokation to fail but passed"); } @Test