### Question:
OcrEngineStarter { public void startOcrWithParams(OcrParameters params) { OcrFactory factory = factoryProvider.createFactory(params.ocrEngine, params.props); engine = factory.createEngine(); FileAccess fileAccess = beanProvider.getFileAccess(); File[] allBookFolders = fileAccess.getAllFolders(params.inputFolder, params.inputFormats); for (File bookFolder : allBookFolders) { OcrProcess process = factory.createProcess(); process.setName(bookFolder.getName()); process.setOutputDir(new File(params.outputFolder)); File[] allPages = fileAccess.getAllImagesFromFolder(bookFolder, params.inputFormats); for (File page : allPages) { process.addImage(page.toURI()); } for (String outFormat : params.outputFormats) { OcrFormat ocrFormat = OcrFormat.valueOf(outFormat.toUpperCase()); process.addOutput(ocrFormat); } for (String lang : params.inputLanguages) { process.addLanguage(new Locale(lang)); } process.setPriority(OcrPriority.fromValue(params.priority)); process.setTextType(OcrTextType.valueOf(params.inputTextType.toUpperCase())); process.setQuality(OcrQuality.BEST); engine.addOcrProcess(process); } Mailer mailer = null; String mailAddress = params.props.getProperty("email"); if (mailAddress != null) { int estimatedExecTime = engine.getEstimatedDurationInSeconds(); mailer = beanProvider.getMailer(); mailer.sendStarted(mailAddress, estimatedExecTime); } engine.recognize(); if (mailAddress != null) { mailer.sendFinished(mailAddress, params.outputFolder); } }  void startOcrWithParams(OcrParameters params);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void shouldRejectIllegalOutputFormat() { prepareOneBookWithOneImage(); OcrParameters params = validParams(); params.outputFormats = new String[]{"illegal"}; starterSut.startOcrWithParams(params); }
@Test(expected=IllegalArgumentException.class) public void shouldRejectIllegalTextType() { prepareOneBookWithOneImage(); OcrParameters params = validParams(); params.inputTextType = "illegal"; starterSut.startOcrWithParams(params); }
@Test(expected=IllegalArgumentException.class) public void shouldRejectIllegalPriority() { prepareOneBookWithOneImage(); OcrParameters params = validParams(); params.priority = "-10"; starterSut.startOcrWithParams(params); }
@Test public void shouldStartEngineDespiteNoFolders() { when(fileAccessMock.getAllFolders(anyString(), any(String[].class))).thenReturn(new File[]{}); starterSut.startOcrWithParams(validParams()); verify(engineMock).recognize(); }
@Test public void shouldStartWithBookAndImage() { prepareOneBookWithOneImage(); starterSut.startOcrWithParams(validParams()); verify(processMock).setName("book1"); verify(engineMock).recognize(); }
@Test public void shouldStartAndSendMails() { prepareOneBookWithOneImage(); OcrParameters params = validParams(); when(engineMock.getEstimatedDurationInSeconds()).thenReturn(1); starterSut.startOcrWithParams(params); verify(mailerMock).sendStarted("test@test.com", 1); verify(engineMock).recognize(); verify(mailerMock).sendFinished("test@test.com", "tmp/output"); }