@Test void selectByIdUsingComments() { final String content = " + " + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|configuration|configuration configuration|-|Always enabled|configuration|-\n" + "|input|the input value|-|Always enabled|configuration.input|-\n" + "|nested|it is nested|-|Always enabled|configuration.nested|dataset\n" + "|datastore|the datastore|-|Always enabled|configuration.nested.datastore|datastore\n" + "|user|the user to log in|unknown|Always enabled|configuration.nested.user|dataset\n" + "|===\n" + "\n" + " + "\n" + "== my2\n" + "\n" + "super my component2\n" + "\n" + " + "=== Configuration\n" + "\n" + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|ds|ds configuration|-|Always enabled|ds|dataset\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===\n" + "\n" + " + "== my2\n" + "\n" + "super my componentv3\n" + "\n" + " + "=== Configuration\n" + "\n" + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===\n" + "\n" + " final DocumentationResourceImpl impl = new DocumentationResourceImpl(); assertEquals("super my component", impl.selectById("my", content, DocumentationResourceImpl.DocumentationSegment.DESCRIPTION).trim()); assertEquals("[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|configuration|configuration configuration|-|Always enabled|configuration|-\n" + "|input|the input value|-|Always enabled|configuration.input|-\n" + "|nested|it is nested|-|Always enabled|configuration.nested|dataset\n" + "|datastore|the datastore|-|Always enabled|configuration.nested.datastore|datastore\n" + "|user|the user to log in|unknown|Always enabled|configuration.nested.user|dataset\n" + "|===", impl.selectById("my", content, DocumentationResourceImpl.DocumentationSegment.CONFIGURATION).trim()); assertEquals( "== my\n" + "\n" + "super my component\n" + "\n" + " + "=== Configuration\n" + "\n" + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|configuration|configuration configuration|-|Always enabled|configuration|-\n" + "|input|the input value|-|Always enabled|configuration.input|-\n" + "|nested|it is nested|-|Always enabled|configuration.nested|dataset\n" + "|datastore|the datastore|-|Always enabled|configuration.nested.datastore|datastore\n" + "|user|the user to log in|unknown|Always enabled|configuration.nested.user|dataset\n" + "|===\n" + "\n" + " impl.selectById("my", content, DocumentationResourceImpl.DocumentationSegment.ALL).trim()); assertEquals("super my component2", impl.selectById("my2", content, DocumentationResourceImpl.DocumentationSegment.DESCRIPTION).trim()); assertEquals( "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|ds|ds configuration|-|Always enabled|ds|dataset\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===", impl.selectById("my2", content, DocumentationResourceImpl.DocumentationSegment.CONFIGURATION).trim()); assertEquals( "== my2\n" + "\n" + "super my component2\n" + "\n" + " + "=== Configuration\n" + "\n" + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|ds|ds configuration|-|Always enabled|ds|dataset\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===\n" + "\n" + " impl.selectById("my2", content, DocumentationResourceImpl.DocumentationSegment.ALL).trim()); assertEquals("super my componentv3", impl.selectById("my3", content, DocumentationResourceImpl.DocumentationSegment.DESCRIPTION).trim()); assertEquals( "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===", impl.selectById("my3", content, DocumentationResourceImpl.DocumentationSegment.CONFIGURATION).trim()); assertEquals( "== my2\n" + "\n" + "super my componentv3\n" + "\n" + " + "=== Configuration\n" + "\n" + "[cols=\"d,d,m,a,e,d\",options=\"header\"]\n" + "|===\n" + "|Display Name|Description|Default Value|Enabled If|Configuration Path|Configuration Type\n" + "|datastore|the datastore|-|Always enabled|ds.datastore|datastore\n" + "|===\n" + "\n" + " impl.selectById("my3", content, DocumentationResourceImpl.DocumentationSegment.ALL).trim()); }
String selectById(final String name, final String value, final DocumentationSegment segment) { final List<String> lines; try (final BufferedReader reader = new BufferedReader(new StringReader(value))) { lines = reader.lines().collect(toList()); } catch (final IOException e) { throw new IllegalArgumentException(e); } return extractUsingComments(name, lines, segment) .orElseGet(() -> noMarkingCommentFallbackExtraction(name, lines, segment, value)); }
DocumentationResourceImpl implements DocumentationResource { String selectById(final String name, final String value, final DocumentationSegment segment) { final List<String> lines; try (final BufferedReader reader = new BufferedReader(new StringReader(value))) { lines = reader.lines().collect(toList()); } catch (final IOException e) { throw new IllegalArgumentException(e); } return extractUsingComments(name, lines, segment) .orElseGet(() -> noMarkingCommentFallbackExtraction(name, lines, segment, value)); } }
DocumentationResourceImpl implements DocumentationResource { String selectById(final String name, final String value, final DocumentationSegment segment) { final List<String> lines; try (final BufferedReader reader = new BufferedReader(new StringReader(value))) { lines = reader.lines().collect(toList()); } catch (final IOException e) { throw new IllegalArgumentException(e); } return extractUsingComments(name, lines, segment) .orElseGet(() -> noMarkingCommentFallbackExtraction(name, lines, segment, value)); }  }
DocumentationResourceImpl implements DocumentationResource { String selectById(final String name, final String value, final DocumentationSegment segment) { final List<String> lines; try (final BufferedReader reader = new BufferedReader(new StringReader(value))) { lines = reader.lines().collect(toList()); } catch (final IOException e) { throw new IllegalArgumentException(e); } return extractUsingComments(name, lines, segment) .orElseGet(() -> noMarkingCommentFallbackExtraction(name, lines, segment, value)); }  @Override DocumentationContent getDocumentation(final String id, final String language,
            final DocumentationSegment segment); }
DocumentationResourceImpl implements DocumentationResource { String selectById(final String name, final String value, final DocumentationSegment segment) { final List<String> lines; try (final BufferedReader reader = new BufferedReader(new StringReader(value))) { lines = reader.lines().collect(toList()); } catch (final IOException e) { throw new IllegalArgumentException(e); } return extractUsingComments(name, lines, segment) .orElseGet(() -> noMarkingCommentFallbackExtraction(name, lines, segment, value)); }  @Override DocumentationContent getDocumentation(final String id, final String language,
            final DocumentationSegment segment);  }