ReporterParameterParser { static String getOutputFormat(Map<String, String> parameters) { final String outputLong = parameters.get(OUTPUT_FORMAT_PREFIX_LONG); if (outputLong != null) { return outputLong; } else { return Optional.ofNullable(parameters.get(OUTPUT_FORMAT_PREFIX_SHORT)) .orElseGet(() -> { LOGGER.warn("No output format is given."); return DEFAULT_OUTPUT_FORMAT; }); } } private  ReporterParameterParser();   }
@Test public void getOutputFormatFromShortSwitch() { String outputFormat = "CSV"; Map<String, String> parameters = Collections.singletonMap( ReporterParameterParser.OUTPUT_FORMAT_PREFIX_SHORT, outputFormat); final String gottenOutputFormat = ReporterParameterParser.getOutputFormat(parameters); assertThat(gottenOutputFormat).isEqualTo(outputFormat); }
@Test public void getOutputFormatFromLongSwitch() { String outputFormat = "CSV"; Map<String, String> parameters = Collections.singletonMap( ReporterParameterParser.OUTPUT_FORMAT_PREFIX_LONG, outputFormat); final String gottenOutputFormat = ReporterParameterParser.getOutputFormat(parameters); assertThat(gottenOutputFormat).isEqualTo(outputFormat); }
@Test public void getOutputFormatMissingParameter() { String wrongParameterPrefix = "--some-parameter="; String outputFormat = "something"; Map<String, String> parameters = Collections.singletonMap(wrongParameterPrefix, outputFormat); final String setOutputFormat = ReporterParameterParser.getOutputFormat(parameters); assertThat(setOutputFormat).isEqualTo(DEFAULT_OUTPUT_FORMAT); }