### Question:
HashRecordProcessor implements RecordProcessor<HashData> { public HashData process(String[] col) throws BadDataException { if (col.length < 8) { throw new BadDataException("too few columns"); } else if (col.length > 8) { throw new BadDataException("too many columns"); } long size = 0; try { size = Long.parseLong(col[4]); } catch (NumberFormatException e) { throw new BadDataException(e); } if (size < 0) { throw new BadDataException("size < 0"); } int prod_code = 0; try { prod_code = Integer.parseInt(col[5]); } catch (NumberFormatException e) { throw new BadDataException(e); } if (prod_code < 0) { throw new BadDataException("prod_code < 0"); } byte[] sha1, md5, crc32; try { sha1 = (byte[]) hex.decode(col[0]); md5 = (byte[]) hex.decode(col[1]); crc32 = (byte[]) hex.decode(col[2]); } catch (DecoderException e) { throw new BadDataException(e); } return new HashData( sha1, md5, crc32, col[3], size, prod_code, col[6], col[7] ); }  HashData process(String[] col);  }### Answer:
@Test(expected=BadDataException.class) public void processTooFewCols() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { "foo" }); }
@Test(expected=BadDataException.class) public void processTooManyCols() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); final String[] cols = new String[9]; Arrays.fill(cols, "foo"); proc.process(cols); }
@Test(expected=BadDataException.class) public void processNegativeSize() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, String.valueOf(-1), String.valueOf(prod_code), os_code, special_code }); }
@Test(expected=BadDataException.class) public void processNonnumericSize() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, "foo", String.valueOf(prod_code), os_code, special_code }); }
@Test(expected=BadDataException.class) public void processNegativeProdCode() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, String.valueOf(size), "-1", os_code, special_code }); }
@Test(expected=BadDataException.class) public void processNonnumericProdCode() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, String.valueOf(size), "foo", os_code, special_code }); }
@Test public void processJustRightCols() throws BadDataException, DecoderException { final HashData hd = new HashData( sha1, md5, crc32, name, size, prod_code, os_code, special_code); final RecordProcessor<HashData> proc = new HashRecordProcessor(); assertEquals(hd, proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, String.valueOf(size), String.valueOf(prod_code), os_code, special_code })); }