### Question:
BitcoinSerializer extends MessageSerializer { @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); } BitcoinSerializer(NetworkParameters params, boolean parseRetain); @Override void serialize(String name, byte[] message, OutputStream out); @Override void serialize(Message message, OutputStream out); @Override Message deserialize(ByteBuffer in); @Override BitcoinPacketHeader deserializeHeader(ByteBuffer in); @Override Message deserializePayload(BitcoinPacketHeader header, ByteBuffer in); NetworkParameters getParameters(); @Override AddressMessage makeAddressMessage(byte[] payloadBytes, int length); @Override Message makeAlertMessage(byte[] payloadBytes); @Override Block makeBlock(final byte[] payloadBytes, final int offset, final int length); @Override Message makeBloomFilter(byte[] payloadBytes); @Override FilteredBlock makeFilteredBlock(byte[] payloadBytes); @Override InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length); @Override Transaction makeTransaction(byte[] payloadBytes, int offset,
                                       int length, byte[] hash); @Override void seekPastMagicBytes(ByteBuffer in); @Override boolean isParseRetainMode();  }### Answer:
@Test(expected = Error.class) public void testSerializeUnknownMessage() throws Exception { MessageSerializer serializer = MAINNET.getDefaultSerializer(); Message unknownMessage = new Message() { @Override protected void parse() throws ProtocolException { } }; ByteArrayOutputStream bos = new ByteArrayOutputStream(ADDRESS_MESSAGE_BYTES.length); serializer.serialize(unknownMessage, bos); }