### Question:
RawRecordConfigParser implements ConfigParser<RawRecordConfig, RecordConfig> { @Override public @NonNull RecordConfig parse(final @Nullable RawRecordConfig config) { Objects.requireNonNull(config); final Set<RecordType> allowedTypes; final String topic = Optional.ofNullable(config.topic).orElse(defaults.getTopic()); if (config.type != null) { allowedTypes = EnumSet.noneOf(RecordType.class); get(config.type, Collections.<String>emptyList(), ConfigParserUtil::splitCommaSeparatedString) .forEach(t -> allowedTypes.add(AllowedType.forName(t).getRecordType())); } else { allowedTypes = defaults.getAllowedTypes(); } return new RecordConfig(allowedTypes, topic); } RawRecordConfigParser();  RawRecordConfigParser(final @NonNull RecordConfig defaults); @Override @NonNull RecordConfig parse(final @Nullable RawRecordConfig config);  }### Answer:
@Test public void shouldParseAllowedTypes() { final RawRecordConfig config = new RawRecordConfig(); config.type = String.format("%s,%s", AllowedType.COMMAND.getTypeName(), AllowedType.EVENT.getTypeName()); final RecordConfig parsed = parser.parse(config); assertThat(parsed.getAllowedTypes()) .containsExactlyInAnyOrder(RecordType.COMMAND, RecordType.EVENT); }
@Test public void shouldParseTopic() { final RawRecordConfig config = new RawRecordConfig(); config.topic = "something"; final RecordConfig parsed = parser.parse(config); assertThat(parsed.getTopic()).isEqualTo("something"); }
@Test public void shouldSetDefaultsIfNull() { final RawRecordConfig config = new RawRecordConfig(); final RecordConfig parsed = parser.parse(config); assertThat(parsed.getTopic()).isEqualTo(RawRecordConfigParser.DEFAULT_TOPIC_NAME); assertThat(parsed.getAllowedTypes()).isEqualTo(RawRecordConfigParser.DEFAULT_ALLOWED_TYPES); }
@Test public void shouldSetExplicitDefaultsIfNull() { final RecordConfig defaults = new RecordConfig(EnumSet.allOf(RecordType.class), "topic"); final RawRecordConfigParser explicitParser = new RawRecordConfigParser(defaults); final RawRecordConfig config = new RawRecordConfig(); final RecordConfig parsed = explicitParser.parse(config); assertThat(parsed.getTopic()).isEqualTo(defaults.getTopic()); assertThat(parsed.getAllowedTypes()).isEqualTo(defaults.getAllowedTypes()); }
@Test public void shouldThrowExceptionIfAllowedTypeIsUnknown() { final RawRecordConfig config = new RawRecordConfig(); config.type = "something unlikely"; assertThatThrownBy(() -> parser.parse(config)).isInstanceOf(IllegalArgumentException.class); }