### Question:
CDRMETSDepositHandler extends AbstractDepositHandler { @Override public PID doDeposit(PID destination, DepositData deposit) throws DepositException { log.debug("Preparing to perform a DCR METS deposit to {}", destination.getQualifiedId()); PID depositPID = pidMinter.mintDepositRecordPid(); File metsFile = writeStreamToDataDir(depositPID, deposit); deposit.setSourceUri(metsFile.toPath().normalize().toUri()); MetsHeaderScanner scanner = new MetsHeaderScanner(); try { scanner.scan(metsFile, deposit.getFilename()); } catch (Exception e1) { throw new DepositException( "Unable to parse your METS file: " + deposit.getFilename(), e1); } Map<String, String> status = new HashMap<>(); status.put(DepositField.packageProfile.name(), scanner.getProfile()); status.put(DepositField.metsType.name(), scanner.getType()); status.put(DepositField.createTime.name(), scanner.getCreateDate()); status.put(DepositField.intSenderDescription.name(), StringUtils.join(scanner.getNames(), ',')); registerDeposit(depositPID, destination, deposit, status); return depositPID; }  @Override PID doDeposit(PID destination, DepositData deposit);  }### Answer:
@Test(expected = DepositException.class) public void testNoInputStream() throws Exception { DepositData deposit = new DepositData(null, FILENAME, MIMETYPE, METS_CDR, DEPOSIT_METHOD, depositingAgent); depositHandler.doDeposit(destPid, deposit); }
@Test public void testValidDeposit() throws Exception { InputStream fileStream = getMETSInputStream(); DepositData deposit = new DepositData(fileStream, FILENAME, MIMETYPE, METS_CDR, DEPOSIT_METHOD, depositingAgent); PID depositPid = depositHandler.doDeposit(destPid, deposit); verify(depositStatusFactory).save(eq(depositPid.getId()), statusCaptor.capture()); Map<String, String> status = statusCaptor.getValue(); verifyDepositFields(depositPid, status); }
@Test public void testFilenameWithModifiers() throws Exception { String modifierFilename = ".././" + FILENAME; InputStream fileStream = getMETSInputStream(); DepositData deposit = new DepositData(fileStream, modifierFilename, MIMETYPE, METS_CDR, DEPOSIT_METHOD, depositingAgent); PID depositPid = depositHandler.doDeposit(destPid, deposit); verify(depositStatusFactory).save(eq(depositPid.getId()), statusCaptor.capture()); Map<String, String> status = statusCaptor.getValue(); verifyDepositFields(depositPid, status); }
@Test(expected = DepositException.class) public void testInvalidMETS() throws Exception { InputStream fileStream = new ByteArrayInputStream("Not mets".getBytes()); DepositData deposit = new DepositData(fileStream, FILENAME, MIMETYPE, METS_CDR, DEPOSIT_METHOD, depositingAgent); depositPid = depositHandler.doDeposit(destPid, deposit); }
@Test(expected = DepositException.class) public void testDepositsDirNotAvailable() throws Exception { depositsDir.delete(); InputStream fileStream = getMETSInputStream(); DepositData deposit = new DepositData(fileStream, FILENAME, MIMETYPE, METS_CDR, DEPOSIT_METHOD, depositingAgent); depositHandler.doDeposit(destPid, deposit); }