@Test public void testCreateRequest() throws Exception { tested = createPartialMock(AbstractXMLRequestCreatorBase.class, "convertDocumentToByteArray", "createBody", "generateRandomId"); mockStatic(DocumentHelper.class); final String[] params = new String[] { "String1", "String2" }; final byte[] expected = new byte[] { 42 }; expect(DocumentHelper.createDocument()).andReturn(documentMock); expect(documentMock.addElement(XMLProtocol.ENCODE_ELEMENT)).andReturn(rootElementMock); expect(rootElementMock.addElement(XMLProtocol.HEADER_ELEMENT)).andReturn(headerElementMock); final String id = "213"; expect(tested.generateRandomId()).andReturn(id); expect(headerElementMock.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, id)).andReturn(null); expect(rootElementMock.addElement(XMLProtocol.BODY_ELEMENT)).andReturn(bodyElementMock); tested.createBody(bodyElementMock, params); expectLastCall().times(1); expect(tested.convertDocumentToByteArray(documentMock)).andReturn(expected); replayAll(); replay(DocumentHelper.class); byte[] actual = tested.createRequest(params); verifyAll(); verify(DocumentHelper.class); assertArrayEquals(expected, actual); }
public final byte[] createRequest(String... params) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(XMLProtocol.ENCODE_ELEMENT); Element header = root.addElement(XMLProtocol.HEADER_ELEMENT); header.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, generateRandomId()); Element body = root.addElement(XMLProtocol.BODY_ELEMENT); createBody(body, params); byte[] array = null; try { array = convertDocumentToByteArray(document); } catch (IOException e) { throw new RuntimeException("Failed to create request", e); } return array; }
AbstractXMLRequestCreatorBase { public final byte[] createRequest(String... params) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(XMLProtocol.ENCODE_ELEMENT); Element header = root.addElement(XMLProtocol.HEADER_ELEMENT); header.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, generateRandomId()); Element body = root.addElement(XMLProtocol.BODY_ELEMENT); createBody(body, params); byte[] array = null; try { array = convertDocumentToByteArray(document); } catch (IOException e) { throw new RuntimeException("Failed to create request", e); } return array; } }
AbstractXMLRequestCreatorBase { public final byte[] createRequest(String... params) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(XMLProtocol.ENCODE_ELEMENT); Element header = root.addElement(XMLProtocol.HEADER_ELEMENT); header.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, generateRandomId()); Element body = root.addElement(XMLProtocol.BODY_ELEMENT); createBody(body, params); byte[] array = null; try { array = convertDocumentToByteArray(document); } catch (IOException e) { throw new RuntimeException("Failed to create request", e); } return array; }  }
AbstractXMLRequestCreatorBase { public final byte[] createRequest(String... params) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(XMLProtocol.ENCODE_ELEMENT); Element header = root.addElement(XMLProtocol.HEADER_ELEMENT); header.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, generateRandomId()); Element body = root.addElement(XMLProtocol.BODY_ELEMENT); createBody(body, params); byte[] array = null; try { array = convertDocumentToByteArray(document); } catch (IOException e) { throw new RuntimeException("Failed to create request", e); } return array; }  byte[] convertDocumentToByteArray(Document document); final byte[] createRequest(String... params); }
AbstractXMLRequestCreatorBase { public final byte[] createRequest(String... params) { Document document = DocumentHelper.createDocument(); Element root = document.addElement(XMLProtocol.ENCODE_ELEMENT); Element header = root.addElement(XMLProtocol.HEADER_ELEMENT); header.addAttribute(XMLProtocol.HEADER_MSG_ID_ATTRIBUTE, generateRandomId()); Element body = root.addElement(XMLProtocol.BODY_ELEMENT); createBody(body, params); byte[] array = null; try { array = convertDocumentToByteArray(document); } catch (IOException e) { throw new RuntimeException("Failed to create request", e); } return array; }  byte[] convertDocumentToByteArray(Document document); final byte[] createRequest(String... params);  }