AsciiDocParser { public Map<String, List<String>> serializeKindFilenameTable(final InputStream table) { final Map<String, List<String>> serializedContent = new HashMap<>(); try (final BufferedReader tableContent = new BufferedReader(new InputStreamReader(table))) { skipUntilColumns(tableContent); boolean endTable = false; while (!endTable) { final List<String> readRow = readRow(tableContent); final String separator = readEmptyLineOrEndTable(tableContent); String kind = readRow.get(0); serializedContent.put(kind, readRow.subList(1, readRow.size())); if (END_TABLE.equals(separator)) { endTable = true; } } } catch (IOException e) { throw new IllegalStateException(e); } return serializedContent; }  Map<String, List<String>> serializeKindFilenameTable(final InputStream table);  }
@Test public void should_serialize_kind_and_filename_from_valid_asciidoc_table() { final AsciiDocParser asciiDocParser = new AsciiDocParser(); final ByteArrayInputStream tableContent = new ByteArrayInputStream(VALID_TABLE.getBytes()); final Map<String, List<String>> serializedContent = asciiDocParser.serializeKindFilenameTable(tableContent); final Map<String, List<String>> expectedSerlializedContent = new HashMap<>(); expectedSerlializedContent.put("ConfigMap", Arrays.asList("cm", "configmap")); expectedSerlializedContent.put("CronJob", Arrays.asList("cronjob")); assertThat(serializedContent) .containsAllEntriesOf(expectedSerlializedContent); }
@Test public void should_throw_exception_if_no_end_of_table() { final AsciiDocParser asciiDocParser = new AsciiDocParser(); final ByteArrayInputStream tableContent = new ByteArrayInputStream(NONE_END_VALID_TABLE.getBytes()); Throwable error = catchThrowable(() -> asciiDocParser.serializeKindFilenameTable(tableContent)); assertThat(error).isInstanceOf(IllegalArgumentException.class); }
@Test public void should_throw_exception_if_more_than_two_columns_are_present() { final AsciiDocParser asciiDocParser = new AsciiDocParser(); final ByteArrayInputStream tableContent = new ByteArrayInputStream(INVALID_TABLE_WITH_THREE_COLUMNS.getBytes()); Throwable error = catchThrowable(() -> asciiDocParser.serializeKindFilenameTable(tableContent)); assertThat(error).isInstanceOf(IllegalArgumentException.class); }