### Question:
Main { void execute(String[] args) throws UnsupportedEncodingException { initOptions(args); if (terminated) { return; } OcrParameters params = transformOptions(); if (terminated) { return; } String validationMessage = paramValidator.validateParameters(params); if ("OK".equals(validationMessage)) { out.println("Starting OCR..."); engineStarter.startOcrWithParams(params); out.println("Finished OCR."); } else { out.println("Illegal options: " + validationMessage); } }  static void main(String[] args);  }### Answer:
@Test public void shouldPrintHelp() throws UnsupportedEncodingException { main.execute(new String[]{"-help"}); String outString = new String(baos.toByteArray()); assertThat(outString, containsString("usage: java -jar")); assertThat(outString, containsString("-help")); }
@Test public void shouldDenyWrongArgument() throws UnsupportedEncodingException { main.execute(new String[]{"-wrongargument"}); String outString = new String(baos.toByteArray()); assertThat(outString, containsString("Illegal arguments. Use -help.")); }
@Test public void shouldPassAllParams() throws UnsupportedEncodingException { ArgumentCaptor<OcrParameters> captor = ArgumentCaptor.forClass(OcrParameters.class); when(validatorMock.validateParameters(any(OcrParameters.class))).thenReturn("OK"); main.execute(validOptions()); verify(validatorMock).validateParameters(captor.capture()); OcrParameters param = captor.getValue(); assertEquals("/tmp/in", param.inputFolder); assertEquals("tif", param.inputFormats[0]); assertEquals("jpg", param.inputFormats[1]); assertEquals("normal", param.inputTextType); assertEquals("de", param.inputLanguages[0]); assertEquals("en", param.inputLanguages[1]); assertEquals("/tmp/out", param.outputFolder); assertEquals("pdf", param.outputFormats[0]); assertEquals("xml", param.outputFormats[1]); assertEquals("2", param.priority); assertEquals("abbyy", param.ocrEngine); assertEquals("me", param.props.get("user")); assertEquals("pass", param.props.get("password")); }
@Test public void shouldComplainAboutMissingOptions() throws UnsupportedEncodingException { main.execute(new String[]{"-indir", "/tmp"}); String outString = new String(baos.toByteArray()); assertThat(outString, containsString("Required options are missing. Use -help.")); }
@Test public void shouldStartEngine() throws UnsupportedEncodingException { when(validatorMock.validateParameters(any(OcrParameters.class))).thenReturn("OK"); main.execute(validOptions()); verify(engineStarterMock).startOcrWithParams(any(OcrParameters.class)); }
@Test public void shouldNotStartEngine() throws UnsupportedEncodingException { when(validatorMock.validateParameters(any(OcrParameters.class))).thenReturn("Input folder does not exist"); main.execute(validOptions()); verify(engineStarterMock, times(0)).startOcrWithParams(any(OcrParameters.class)); String outString = new String(baos.toByteArray()); assertThat(outString, containsString("Illegal options: Input folder does not exist")); }
@Test public void shouldSetDefaultValues() throws UnsupportedEncodingException { ArgumentCaptor<OcrParameters> captor = ArgumentCaptor.forClass(OcrParameters.class); main.execute(onlyRequiredOptions()); verify(validatorMock).validateParameters(captor.capture()); OcrParameters param = captor.getValue(); assertEquals("tif", param.inputFormats[0]); assertEquals("jpg", param.inputFormats[1]); assertEquals("gif", param.inputFormats[2]); assertEquals("0", param.priority); assertEquals("abbyy", param.ocrEngine); assertNotNull(param.props); }