### Question:
Connector { static ConnectDetails read(InputStream in) throws CommunicationException { try { final ObjectInputStream objectInputStream = new ObjectInputStream(in); final ConnectionType type = (ConnectionType) objectInputStream.readObject(); final Address address = (Address) objectInputStream.readObject(); return new ConnectDetails(type, address); } catch (IOException e) { throw new CommunicationException("Could not read address details", e); } catch (ClassNotFoundException e) { throw new CommunicationException("Could not read address details", e); } } Connector(String hostString,
                   int port,
                   ConnectionType connectionType); @Override int hashCode(); @Override boolean equals(Object o); String getEndpointAsString();  }### Answer:
@Test public void testBadRead() throws Exception { final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out); for (int x = 0; x < 100; ++x) { out.write(99); } try { Connector.read(in); fail("Expected CommunicationException"); } catch (CommunicationException e) { } final ObjectOutputStream objectStream = new ObjectOutputStream(out); objectStream.writeObject(ConnectionType.WORKER); objectStream.write(99); objectStream.writeObject(null); try { Connector.read(in); fail("Expected CommunicationException"); } catch (CommunicationException e) { } while (in.available() > 0) { in.read(); } objectStream.writeObject(ConnectionType.WORKER); objectStream.writeObject(IsolatedObjectFactory.getIsolatedObject()); try { Connector.read(in); fail("Expected CommunicationException"); } catch (CommunicationException e) { } }