|
| 1 | +/* |
| 2 | + * Copyright 2003-2008 Terracotta, Inc. |
| 3 | + * Copyright Super iPaaS Integration LLC, an IBM Company 2024 |
| 4 | + */ |
| 5 | + |
| 6 | +package com.tc.object.management; |
| 7 | + |
| 8 | +import com.tc.util.Assert; |
| 9 | +import java.io.ByteArrayOutputStream; |
| 10 | +import java.io.ObjectOutputStream; |
| 11 | +import org.junit.After; |
| 12 | +import org.junit.AfterClass; |
| 13 | +import org.junit.Before; |
| 14 | +import org.junit.BeforeClass; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +/** |
| 18 | + * |
| 19 | + */ |
| 20 | +public class SerializationHelperTest { |
| 21 | + |
| 22 | + public SerializationHelperTest() { |
| 23 | + } |
| 24 | + |
| 25 | + @BeforeClass |
| 26 | + public static void setUpClass() { |
| 27 | + } |
| 28 | + |
| 29 | + @AfterClass |
| 30 | + public static void tearDownClass() { |
| 31 | + } |
| 32 | + |
| 33 | + @Before |
| 34 | + public void setUp() { |
| 35 | + } |
| 36 | + |
| 37 | + @After |
| 38 | + public void tearDown() { |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testArrayClassResolve() throws Exception { |
| 43 | + byte[] raw; |
| 44 | + String[] sa = new String[] {"foo", "bar", "baz"}; |
| 45 | + |
| 46 | + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 47 | + ObjectOutputStream oo = new ObjectOutputStream(out)) { |
| 48 | + oo.writeObject(sa); |
| 49 | + oo.flush(); |
| 50 | + raw = out.toByteArray(); |
| 51 | + } |
| 52 | + |
| 53 | + Object check = SerializationHelper.deserialize(raw, getClass().getClassLoader()); |
| 54 | + Assert.assertTrue(check, check.getClass().isArray()); |
| 55 | + Assert.assertTrue(check, check.getClass().getComponentType().isAssignableFrom(String.class)); |
| 56 | + String[] look = (String[])check; |
| 57 | + Assert.assertEquals(sa.length, look.length); |
| 58 | + for (int x=0;x<sa.length;x++) { |
| 59 | + Assert.assertEquals(sa[x], look[x]); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testMultiArrayResolve() throws Exception { |
| 66 | + byte[] raw; |
| 67 | + String[][] sa = new String[][] {{"foo"}, {"bar"}, {"baz"}}; |
| 68 | + |
| 69 | + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 70 | + ObjectOutputStream oo = new ObjectOutputStream(out)) { |
| 71 | + oo.writeObject(sa); |
| 72 | + oo.flush(); |
| 73 | + raw = out.toByteArray(); |
| 74 | + } |
| 75 | + |
| 76 | + Object check = SerializationHelper.deserialize(raw, getClass().getClassLoader()); |
| 77 | + Assert.assertTrue(check, check.getClass().isArray()); |
| 78 | + Assert.assertTrue(check, check.getClass().getComponentType().isArray()); |
| 79 | + } |
| 80 | +} |
0 commit comments