### Question:
KeypairService { public String getPEM(PrivateKey privKey) { StringWriter stringWriter = new StringWriter(); PEMWriter pemWriter = new PEMWriter(stringWriter); try { pemWriter.writeObject(privKey); pemWriter.close(); } catch (IOException e) { e.printStackTrace(); } String privKeyString = stringWriter.toString(); return privKeyString; }  KeyPair createKeypair(); String getPEM(PrivateKey privKey); String getPublicKeyString(PublicKey pubKey);  }### Answer:
@Test public void testGetPEM() { KeyPair kp = keypairService.createKeypair(); PrivateKey privateKey = kp.getPrivate(); String privateKeyString = keypairService.getPEM(privateKey); assertNotNull(privateKeyString); Pattern pattern = Pattern.compile("-----BEGIN RSA PRIVATE KEY-----\\r?\\n.*-----END RSA PRIVATE KEY-----\\r?\\n",Pattern.DOTALL); Matcher regexMatcher = pattern.matcher(privateKeyString); assertTrue(regexMatcher.matches()); }