### Question:
CommandTpm implements Tpm { static int parseNvramSizeFromNvInfoOutput(final String commandOutput) { String[] lines = commandOutput.trim().split("\\r?\\n"); for (String line : lines) { if (line.startsWith("Size")) { String rawSizeValue = line.split(":")[1].trim(); String decimalSizeStr = rawSizeValue.split(" ")[0]; return Integer.parseInt(decimalSizeStr); } } throw new RuntimeException("Failed to find size from EC's NVRAM area"); }  @Override void takeOwnership(); @Override byte[] getEndorsementCredentialModulus(); @Override byte[] getEndorsementCredential(); @Override byte[] collateIdentityRequest(final byte[] acaPublicKey, final String uuid); @Override byte[] activateIdentity(final byte[] asymmetricBlob, final byte[] symmetricBlob,
            final String uuid); @Override byte[] getQuote(final String pcr, final String nonce, final String uuid);  }### Answer:
@Test public void parseSizeValid() { final int expectedSize = 1129; String nvInfoOutput = "\n" + "NVRAM index : 0x1000f000 (268496896)\n" + "PCR read selection:\n" + " Localities : ALL\n" + "PCR write selection:\n" + " Localities : ALL\n" + "Permissions : 0x00020002 (OWNERREAD|OWNERWRITE)\n" + "bReadSTClear : FALSE\n" + "bWriteSTClear : FALSE\n" + "bWriteDefine : FALSE\n" + "Size : 1129 (0x469)\n" + "\n"; int readSize = CommandTpm.parseNvramSizeFromNvInfoOutput(nvInfoOutput); Assert.assertEquals(readSize, expectedSize); }
@Test(expectedExceptions = RuntimeException.class) public void parseSizeMissingSizeValue() { String nvInfoOutput = "\n" + "NVRAM index : 0x1000f000 (268496896)\n" + "PCR read selection:\n" + " Localities : ALL\n" + "PCR write selection:\n" + " Localities : ALL\n" + "Permissions : 0x00020002 (OWNERREAD|OWNERWRITE)\n" + "bReadSTClear : FALSE\n" + "bWriteSTClear : FALSE\n" + "bWriteDefine : FALSE\n" + "Strength : 1129 (0x469)\n" + "\n"; CommandTpm.parseNvramSizeFromNvInfoOutput(nvInfoOutput); }
@Test(expectedExceptions = RuntimeException.class) public void parseSizeBadOutput() { String nvInfoOutput = "bad data here. FAILURE TO READ SOMETHING!"; CommandTpm.parseNvramSizeFromNvInfoOutput(nvInfoOutput); }