### Question:
NoticeResponse extends PGMessage { public boolean addNotice(byte code, String noticeMsg) { if (notices == null) { return false; } notices.add(new Notice(code, noticeMsg)); return true; } NoticeResponse();  NoticeResponse(List<Notice> notices); List<Notice> getNotices(); void setNotices(List<Notice> notices); boolean addNotice(byte code, String noticeMsg); static NoticeResponse loadFromPacket(byte[] packet); @Override String toString();  }### Answer:
@Test public void testToPacket() { byte code = PGFlags.SEVERITY; String msg = Severity.WARNING.name(); NoticeResponse noticeResp = new NoticeResponse(); noticeResp.addNotice(code, msg); byte[] bytes = noticeResp.toPacket(); int expectedDataTotalLen = 1 + 4 + 1 + msg.length() + 1 + 1; assertEquals(bytes.length, expectedDataTotalLen); PGProto proto = new PGProto(bytes); byte expectedDataType = PGFlags.NOTICE_RESPONSE; assertEquals(proto.readByte(), expectedDataType); int expectedDataPayloadLen = expectedDataTotalLen - 1; assertEquals(proto.readInt32(), expectedDataPayloadLen); assertEquals(proto.readByte(), code); assertEquals(proto.readNullStr(), msg); }