### Question:
MetaUtil { public static Header convertResponseToHeader(DefaultResponse response) { Header header = new Header(); int messageType = response.getMessageType(); if (messageType == MessageType.Normal.getValue()) { header.setMessageType((byte) MessageType.Normal.getValue()); } else if (messageType == MessageType.NormalHeartbeat.getValue()) { header.setMessageType((byte) MessageType.NormalHeartbeat.getValue()); } else if (messageType == MessageType.ScannerHeartbeat.getValue()) { header.setMessageType((byte) MessageType.ScannerHeartbeat.getValue()); HeartbeatInfo heartbeatInfo = genScannerHeartbeatInfo(response); header.setHeartbeatInfo(heartbeatInfo); } else { throw new ProtocolException("Deserialize unknown messageType."); } ResponseInfo responseInfo = new ResponseInfo(); responseInfo.setSequenceId(response.getSeq()); responseInfo.setStatus((byte) StatusCode.Success.getValue()); Throwable exception = response.getException(); if (exception != null) { if (exception instanceof ProtocolException) { responseInfo.setStatus((byte) StatusCode.ProtocolException.getValue()); } else if (exception instanceof DegradeException) { responseInfo.setStatus((byte) StatusCode.DegradeException.getValue()); } else if (exception instanceof SecurityException) { responseInfo.setStatus((byte) StatusCode.SecurityException.getValue()); } else if (exception instanceof TransportException) { responseInfo.setStatus((byte) StatusCode.TransportException.getValue()); } else if (exception instanceof ServiceException) { responseInfo.setStatus((byte) StatusCode.ServiceException.getValue()); } else if (exception instanceof ApplicationException) { responseInfo.setStatus((byte) StatusCode.ApplicationException.getValue()); } else { responseInfo.setStatus((byte) RpcException.getValue()); } responseInfo.setMessage(exception.getMessage()); } header.setResponseInfo(responseInfo); header.setGlobalContext(response.getGlobalContexts()); header.setLocalContext(response.getLocalContexts()); return header; }  static Header convertRequestToHeader(DefaultRequest request); static DefaultRequest convertHeaderToRequest(Header header); static DefaultResponse convertHeaderToResponse(Header header); static Header convertResponseToHeader(DefaultResponse response); static RequestHeader convertRequestToOldProtocolHeader(DefaultRequest request); static DefaultRequest convertOldProtocolHeaderToRequest(RequestHeader header, DefaultRequest request); static void recordTraceInfoInDecode(byte[] msgBuff, Object message); static void recordTraceInfoInEncode(byte[] msgBuff, Object message); static void wrapException(Exception exception, DefaultResponse response);  }### Answer:
@Test public void testResponseToHeader() { when(response.getMessageType()).thenReturn(MessageType.Normal.getValue()); Header header = MetaUtil.convertResponseToHeader(response); Assert.assertEquals(header.getMessageType(), MessageType.Normal.getValue()); when(response.getMessageType()).thenReturn(3); try { MetaUtil.convertResponseToHeader(response); } catch (Exception e) { Assert.assertTrue(e instanceof ProtocolException); } when(response.getMessageType()).thenReturn(MessageType.ScannerHeartbeat.getValue()); header = MetaUtil.convertResponseToHeader(response); Assert.assertEquals(header.getMessageType(), MessageType.ScannerHeartbeat.getValue()); when(response.getMessageType()).thenReturn(MessageType.NormalHeartbeat.getValue()); header = MetaUtil.convertResponseToHeader(response); Assert.assertEquals(header.getMessageType(), MessageType.NormalHeartbeat.getValue()); when(response.getException()).thenReturn(new ProtocolException("Mock ProtocolException.")); header = MetaUtil.convertResponseToHeader(response); Assert.assertEquals(header.getResponseInfo().sequenceId, 1L); Assert.assertEquals(header.getResponseInfo().getMessage(), "Mock ProtocolException."); }