### Question:
PcrSelection { public final boolean isPcrSelected(final int pcrNumber) { final int numBitsInByte = 8; final int mostSigBitInByte = 128; if (pcrNumber < 0) { LOGGER.error("negative PCR number"); throw new IndexOutOfBoundsException("negative PCR number"); } int byteIndex = pcrNumber / numBitsInByte; int bitIndex = pcrNumber % numBitsInByte; if (byteIndex > this.pcrSelect.length) { String msg = String.format( "index %d out of bounds, pcrSelect size is %d bytes", byteIndex, this.pcrSelect.length); LOGGER.error(msg); throw new IndexOutOfBoundsException(msg); } return (this.pcrSelect[byteIndex] & (mostSigBitInByte >>> bitIndex)) != 0; } protected  PcrSelection();  PcrSelection(final byte[] pcrSelect);  PcrSelection(final long pcrSelectLong); @XmlAttribute(name = "SizeOfSelect", required = true) @XmlSchemaType(name = "unsignedShort") final int getSizeOfSelect(); final byte[] getPcrSelect(); final boolean isPcrSelected(final int pcrNumber); final String getMaskForTPM(); @Override final int hashCode(); @Override final boolean equals(final Object obj); final int getLength(); final byte[] getValue(); static final int ALL_PCRS_ON; }### Answer:
@Test public final void isPcrSelected() { byte[] selectionBytes = {ON_BITS, OFF_BITS, OFF_BITS}; PcrSelection pcrSelection = new PcrSelection(selectionBytes); for (int i = 0; i < NUM_BITS_IN_BYTE; i++) { Assert.assertTrue(pcrSelection.isPcrSelected(i)); } for (int i = NUM_BITS_IN_BYTE; i < NUM_BITS_IN_BYTE * selectionBytes.length; i++) { Assert.assertFalse(pcrSelection.isPcrSelected(i)); } }
@Test(expectedExceptions = IndexOutOfBoundsException.class) public final void isSelectedNegativeValue() { byte[] selectionBytes = {ON_BITS}; PcrSelection pcrSelection = new PcrSelection(selectionBytes); pcrSelection.isPcrSelected(-1); }