@Test public void testException() throws Exception { Object exceptions[] = { null, new Exception("test"), new ArrayIndexOutOfBoundsException(), new RuntimeException(new IllegalArgumentException("Blub")) }; try { throw new IOException(); } catch (Exception ex) { exceptions[0] = ex; } out.writeObject(exceptions); in.resetForReuseUseArray(out.getCopyOfWrittenBuffer()); out.flush(); Object res[] = (Object[]) in.readObject(); // assertTrue(DeepEquals.deepEquals(obj,res)); for (int i = 0; i < res.length; i++) { Object ex = res[i]; String message = ((Throwable) exceptions[i]).getMessage(); String message1 = ((Throwable) ex).getMessage(); assertTrue(DeepEquals.deepEquals(message, message1)); } }
@Test public void testBigNums() throws Exception { BigNums obj = new BigNums(); out.writeObject(obj); in.resetForReuseUseArray(out.getCopyOfWrittenBuffer()); out.flush(); Object res = in.readObject(); assertTrue(DeepEquals.deepEquals(obj, res)); }
@Test public void testWeirdArray() throws Exception { WeirdArrays obj = new WeirdArrays(); out.writeObject(obj); in.resetForReuseUseArray(lastBinary = out.getCopyOfWrittenBuffer()); out.flush(); WeirdArrays res = (WeirdArrays) in.readObject(); assertTrue(DeepEquals.deepEquals(obj, res)); }
@Test public void testStrings() throws Exception { Strings obj = new Strings(); out.writeObject(obj); in.resetForReuseUseArray(out.getCopyOfWrittenBuffer()); out.flush(); Strings res = (Strings) in.readObject(); assertTrue(DeepEquals.deepEquals(res.junk, res.junk1)); assertTrue(DeepEquals.deepEquals(obj, res)); }
@Test public void testPrimitiveArray() throws Exception { PrimitiveArray obj = new PrimitiveArray(); out.writeObject(obj); in.resetForReuseUseArray(lastBinary = out.getCopyOfWrittenBuffer()); out.flush(); PrimitiveArray res = (PrimitiveArray) in.readObject(); assertTrue(res.aLong0 == res.aRef); assertTrue(res.aRef1 == res.mix[1]); assertTrue(DeepEquals.deepEquals(obj, res)); }
@Test public void testEnums() throws Exception { Basics obj = new Basics(123); out.writeObject(obj); in.resetForReuseUseArray(out.getCopyOfWrittenBuffer()); out.flush(); Basics res = (Basics) in.readObject(); // note: fix false alarm with 1.7_71 + newer 1.8. (because stacktrace not serialized ofc) Object[] exceptions1 = res.exceptions; Object[] exceptions2 = obj.exceptions; res.exceptions = obj.exceptions = null; for (int i = 1; i < exceptions1.length; i++) { assertTrue(exceptions1[i].getClass() == exceptions2[i].getClass()); } assertTrue(DeepEquals.deepEquals(obj, res)); }
@Test public void testSimpleCollections() throws Exception { HashMap obj = new HashMap(); ArrayList li = new ArrayList(); li.add("zero"); li.add(null); li.add("second"); obj.put("x", li); obj.put("y", li); obj.put("yy", null); obj.put(null, "asd"); obj.put(3, "99999"); out.writeObject(obj); final byte[] copyOfWrittenBuffer = out.getCopyOfWrittenBuffer(); in.resetForReuseUseArray(copyOfWrittenBuffer); out.flush(); HashMap res = (HashMap) in.readObject(); assertTrue(res.get("x") == res.get("y")); assertTrue(DeepEquals.deepEquals(obj, res)); }