📄 xmlobjectstreamunit.java
字号:
*/ protected void testMultipleObjects() { try { xoos.writeObject(new Integer(28)); xoos.writeObject(new Vector()); flip(); if (!(xois.readObject().equals(new Integer(28)) || xois.readObject().equals(new Vector()))) { throw new IOException("Objects are not equal!"); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testUnserializableObject() { try { try { xoos.writeObject(new Object()); } catch (NotSerializableException e) { reset(); return; } } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testByteCustomSerializer() { try { TestByteSerialization object = new TestByteSerialization(); xoos.writeObject(object); flip(); System.out.println("XML IS: " + (new String(baos.toByteArray()))); TestByteSerialization object2 = (TestByteSerialization) xois.readObject(); if (object2 == null) { throw new IOException("Object was null!"); } if (object2.bytes() == null) { throw new IOException("Object bytes was null!"); } if (object2.bytes().length != 5) { throw new IOException("Object did not have correct length " + object2.bytes().length); } for (int i = 0; i < 4; i++) { if (object.bytes()[i] != object2.bytes()[i]) { throw new IOException("Object did not have correct byte!"); } } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testCustomSerializer() { try { Object object = new Serializable() { private int hashCode = 83; public int hashCode() { return hashCode; } private void readObject(ObjectInputStream oos) throws IOException, ClassNotFoundException { hashCode = 100; } private void writeObject(ObjectOutputStream oos) throws IOException { } }; xoos.writeObject(object); flip(); Object object2 = xois.readObject(); if (object2.hashCode() != 100) { throw new IOException("Object did not have correct hashCode " + object2.hashCode()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testBrokenCustomSerializer() { try { try { Object object = new Serializable() { private void writeObject(ObjectOutputStream oos) throws IOException { } }; xoos.writeObject(object); flip(); xois.readObject(); } catch (IOException e) { reset(); return; } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testUnshared() { try { Object object = new Integer(3); xoos.writeObject(object); xoos.writeUnshared(object); xoos.writeObject(object); flip(); Object object2 = xois.readObject(); Object object3 = xois.readObject(); Object object4 = xois.readObject(); if ((object2 == object3) || (object3 == object4) || (object2 != object4)) { throw new IOException("Object did not have correct equality " + System.identityHashCode(object2) + " " + System.identityHashCode(object3) + " " + System.identityHashCode(object4)); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testExternal() { try { TestExternalizable object = new TestExternalizable(); xoos.writeObject(object); flip(); TestExternalizable object2 = (TestExternalizable) xois.readObject(); if (object2.getNum() != 299) { throw new IOException("Object did not have correct num " + object2.getNum()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testSubExternal() { try { TestSubExternalizable object = new TestSubExternalizable(null); xoos.writeObject(object); flip(); TestSubExternalizable object2 = (TestSubExternalizable) xois.readObject(); if (object2.getNum() != 1000) { throw new IOException("Object did not have correct num " + object2.getNum()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testPutFields() { try { TestPutFields object = new TestPutFields(); xoos.writeObject(object); flip(); TestPutFields object2 = (TestPutFields) xois.readObject(); if ((object2.getNum() != 10001) || (object2.getNum2() != 99)) { throw new IOException("Object did not have correct num " + object2.getNum() + " " + object2.getNum2()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testUnreadData() { try { TestUnreadData object = new TestUnreadData(); xoos.writeObject(object); flip(); TestUnreadData object2 = (TestUnreadData) xois.readObject(); if (object2.getNum() != object.getNum()) { throw new IOException("Object did not have correct num " + object2.getNum() + " " + object.getNum()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testWriteReplace() { try { TestReplace object = new TestReplace(); xoos.writeObject(object); flip(); Object object2 = xois.readObject(); if (!(object2 instanceof TestReplace2)) { throw new IOException("Object did not have correct class " + object2.getClass()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testReadResolve() { try { TestResolve object = new TestResolve(); xoos.writeObject(object); flip(); Object object2 = xois.readObject(); if (!(object2 instanceof TestResolve2)) { throw new IOException("Object did not have correct class " + object2.getClass()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testInheritedWriteReplace() { try { TestReplace3 object = new TestReplace3(); xoos.writeObject(object); flip(); Object object2 = xois.readObject(); if (!(object2 instanceof TestReplace2)) { throw new IOException("Object did not have correct class " + object2.getClass()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testInheritedReadResolve() { try { TestResolve3 object = new TestResolve3(); xoos.writeObject(object); flip(); Object object2 = xois.readObject(); if (!(object2 instanceof TestResolve2)) { throw new IOException("Object did not have correct class " + object2.getClass()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * A unit test for JUnit */ protected void testSerialPersistentFields() { try { TestSerialPersistentFields object = new TestSerialPersistentFields(); xoos.writeObject(object); flip(); TestSerialPersistentFields object2 = (TestSerialPersistentFields) xois.readObject(); if (!(object2.getNum1().equals(new Integer(1)) && (object2.getNum2() == null))) { throw new IOException("Object did not have correct nums " + object2.getNum1() + " " + object2.getNum2()); } reset(); } catch (IOException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("test produced exception " + e); e.printStackTrace(); } } /** * DESCRIBE THE METHOD */ public void start() { testInt(20930); testInt(0); testInt(-29384); testBoolean(true); testBoolean(false); testByte((byte) 0); testByte((byte) 10); testByte((byte) 255); testChar('A'); testChar('B'); testChar('z'); testChar('1'); testChar('.'); testChar('&'); testChar('<'); testChar('>'); testChar(' '); testChar('"'); testChar('\''); testDouble((double) 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -